自定义对话框包含RecyclerView时遇到的context问题

我想做一个排行榜,就是用自定义的对话框包含一个recyclerView实现展示。以下是自定义的对话框类部分。在写到设置recyclerView的layoutManager的时候遇到问题,context不知道怎么处理,也就是“LinearLayoutManager layoutManager=new LinearLayoutManager(**this**);”的this报错,说:
LinearLayoutManager(android.content.Context)in LinearLayoutManager cannot be applied to (com.example.schoolpet.MyDialog)
由于我对android的context实在还没能理解,求助各位

public class MyDialog extends Dialog {
Activity context;
public RecyclerView recyclerView;
private View.OnClickListener mClickListener;
private List rankingLists=new ArrayList<>();
public Context context1;
public PetPage petPage;

public MyDialog(Activity context) {
    super(context);
    this.context = context;
}

public MyDialog(Activity context, int theme, View.OnClickListener clickListener) {
    super(context, theme);
    this.context = context;
    this.mClickListener = clickListener;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 指定布局
    this.setContentView(R.layout.ranking_list);

    initRankingList();
    recyclerView=(RecyclerView)findViewById(R.id.rankingList_recyclerView);
    LinearLayoutManager layoutManager=new LinearLayoutManager(**this**);
    recyclerView.setLayoutManager(layoutManager);
    RankingListAdapter adapter=new RankingListAdapter(rankingLists);
    recyclerView.setAdapter(adapter);

    /*
     * 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置, 可以直接调用getWindow(),表示获得这个Activity的Window
     * 对象,这样这可以以同样的方式改变这个Activity的属性.
     */
    Window dialogWindow = this.getWindow();
    WindowManager m = context.getWindowManager();
    Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
    WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
    p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
    p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.8
    dialogWindow.setAttributes(p);

    this.setCancelable(true);

}

private void initRankingList() {
    RankingList rankingList=new RankingList(1,"林辉",30,30);
    rankingLists.add(rankingList);
    RankingList rankingList2=new RankingList(2,"林辉",30,30);
    rankingLists.add(rankingList);
    RankingList rankingList3=new RankingList(3,"林辉",30,30);
    rankingLists.add(rankingList);
    RankingList rankingList4=new RankingList(4,"林辉",30,30);
    rankingLists.add(rankingList);
}

}

2个回答

把 ** ** 都去了 就差不多了。

(**this**)换成context

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
安卓中自定义对话框的显示问题

android中自定义的dialog,为甚么会出现一块没有设置的背景呢》下面给出源码和效果图。 自定义dialog的布局xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center_horizontal" android:background="@drawable/custom_dialog"> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="提示" android:textSize="20sp" android:layout_marginTop="20dp"/> <TextView android:id="@+id/tv_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="是否删除?" android:layout_marginBottom="20dp" android:textSize="20sp" android:layout_marginTop="20dp"/> <View android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#000000" /> <LinearLayout android:layout_width="match_parent" android:layout_height="45dp" android:orientation="horizontal" > <TextView android:id="@+id/tv_confirm" android:gravity="center" android:layout_width="0dp" android:layout_height="45dp" android:layout_weight="1" android:text="确定" android:textSize="20sp" /> <View android:layout_width="0.5dp" android:layout_height="45dp" android:background="#000000" /> <TextView android:id="@+id/tv_cancel" android:gravity="center" android:layout_width="0dp" android:layout_height="45dp" android:layout_weight="1" android:text="取消" android:textSize="20sp" /> </LinearLayout> </LinearLayout> 自定义Dialog的java代码 package Dialog; import android.app.Dialog; import android.content.Context; import android.graphics.Point; import android.os.Bundle; import android.text.TextUtils; import android.view.Display; import android.view.Gravity; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.TextView; import uilist.ldm.com.uilist.R; import static uilist.ldm.com.uilist.R.id.dialog; /** * Created by Administrator on 2017/9/20 0020. */ public class DialogStyle extends Dialog implements View.OnClickListener { private TextView tv_title,tv_message,tv_confirm,tv_cancel; private IOnCanelListener canelListener; private IOnConfirmListener confirmListener; private String title,message,confirm,cancel; public DialogStyle(Context context) { super(context); } public DialogStyle(Context context,int themeId) { super(context,themeId); } public DialogStyle setTitle(String title) { this.title = title; return this; } public DialogStyle setMessage(String message) { this.message = message; return this; } public DialogStyle setConfirm(String confirm,IOnConfirmListener listener) { this.confirm = confirm; this.confirmListener=listener; return this; } public DialogStyle setCancel(String cancel,IOnCanelListener listener) { this.cancel = cancel; this.canelListener=listener; return this; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialogstyle); //设置宽度 WindowManager m=getWindow().getWindowManager(); Display d=m.getDefaultDisplay(); WindowManager.LayoutParams p=getWindow().getAttributes(); Point size=new Point(); d.getSize(size); p.width=(int)(size.x*0.8);//设置dialog的宽度为当前手机屏幕的80% getWindow().setAttributes(p); tv_title= (TextView) findViewById(R.id.tv_title); tv_message= (TextView) findViewById(R.id.tv_message); tv_confirm= (TextView) findViewById(R.id.tv_confirm); tv_cancel= (TextView) findViewById(R.id.tv_cancel); //设置文字 if(!TextUtils.isEmpty(title)){ tv_title.setText(title); } if(!TextUtils.isEmpty(message)){ tv_message.setText(message); } if(!TextUtils.isEmpty(confirm)){ tv_confirm.setText(confirm); } if(!TextUtils.isEmpty(cancel)){ tv_cancel.setText(cancel); } //设置监听 tv_confirm.setOnClickListener(this); tv_cancel.setOnClickListener(this); } public interface IOnCanelListener{ void onCancel(DialogStyle dialog); } public interface IOnConfirmListener{ void onConfirm(DialogStyle dialog); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.tv_cancel: if(canelListener!=null){ canelListener.onCancel(this); } dismiss(); break; case R.id.tv_confirm: if(confirmListener!=null){ confirmListener.onConfirm(this); } dismiss(); break; default: break; } }} 以及Dialog的shape设置 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ffffff"/> <corners android:radius="10dp"/> </shape> activity中的监听事件 case R.id. dialog1: DialogStyle dialog=new DialogStyle(DialogListActivity.this); dialog.setTitle("提示").setMessage("确认是否删除当前内容").setCancel("取消", new DialogStyle.IOnCanelListener() { @Override public void onCancel(DialogStyle dialog) { Toast.makeText(DialogListActivity.this,"取消",Toast.LENGTH_LONG).show(); } }).setConfirm("确认", new DialogStyle.IOnConfirmListener() { @Override public void onConfirm(DialogStyle dialog) { Toast.makeText(DialogListActivity.this,"确定",Toast.LENGTH_LONG).show(); } }).show(); break; 效果图: ![图片说明](https://img-ask.csdn.net/upload/201709/20/1505893726_503231.png)

自定义对话框显示不出来

继承Dialog的代码: import android.app.Dialog; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Shader; import android.graphics.SweepGradient; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager.LayoutParams; public class ColorPickerDialog extends Dialog { private final int COLOR_DIALOG_WIDTH = 300; private final int COLOR_DIALOG_HEIGHT = 300; private final int CENTER_X = COLOR_DIALOG_WIDTH / 2; private final int CENTER_Y = COLOR_DIALOG_HEIGHT / 2; private final int CENTER_RADIUS = 32; public interface OnColorChangedListener { void colorChanged(int color); } private OnColorChangedListener mListener; private int mInitialColor; public ColorPickerDialog(Context context, OnColorChangedListener listener, int initialColor) { super(context); mListener = listener; mInitialColor = initialColor; } private class ColorPickerView extends View { private Paint mPaint; private Paint mCenterPaint; private final int[] mColors; // 颜色带的起始颜色 private OnColorChangedListener mListener; private boolean mTrackingCenter; private boolean mHightlightCenter; private static final float PI = 3.1415926f; public ColorPickerView(Context c, OnColorChangedListener listener, int color) { super(c); mListener = listener; mColors = new int[] { 0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00, 0xFFFFFF00, 0xFFFF0000 }; Shader s = new SweepGradient(0, 0, mColors, null); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setShader(s); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(32); mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mCenterPaint.setColor(color); mCenterPaint.setStrokeWidth(5); } @Override protected void onDraw(Canvas canvas) { float r = CENTER_X - mPaint.getStrokeWidth() * 0.5f - 20; canvas.translate(CENTER_X, CENTER_Y); canvas.drawCircle(0, 0, r, mPaint); canvas.drawCircle(0, 0, CENTER_RADIUS, mCenterPaint); if(mTrackingCenter) { int c = mCenterPaint.getColor(); mCenterPaint.setStyle(Paint.Style.STROKE); if(mHightlightCenter) { mCenterPaint.setAlpha(0xFF); } else { mCenterPaint.setAlpha(0x00); } canvas.drawCircle(0, 0, CENTER_RADIUS + mCenterPaint.getStrokeWidth(), mCenterPaint); mCenterPaint.setStyle(Paint.Style.FILL); mCenterPaint.setColor(c); } } private int ave(int s, int d, float p) { return s + Math.round(p * (d - s)); } private int interpColor(int colors[], float unit) { if(unit <= 0) return colors[0]; if(unit >=1) return colors[colors.length - 1]; float p = unit * (colors.length - 1); int i = (int)p; p-=i; int c0 = colors[i]; int c1 = colors[i+1]; int a = ave(Color.alpha(c0), Color.alpha(c1), p); int r = ave(Color.red(c0), Color.red(c1), p); int g = ave(Color.green(c0), Color.green(c1), p); int b = ave(Color.blue(c0), Color.green(c1), p); return Color.argb(a,r,g,b); } @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX() - CENTER_X; float y = event.getY() - CENTER_Y; boolean inCenter = Math.sqrt(x*x+y*y) <= CENTER_RADIUS; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTrackingCenter = inCenter; if(inCenter) { mHightlightCenter = true; invalidate(); break; } case MotionEvent.ACTION_MOVE: float angle = (float)Math.atan2(y, x); float unit = angle/(2*PI); if(unit < 0) unit+=1; mCenterPaint.setColor(interpColor(mColors, unit)); invalidate(); break; case MotionEvent.ACTION_UP: if(mTrackingCenter) { if(inCenter) { mListener.colorChanged(mCenterPaint.getColor()); } mTrackingCenter =false; invalidate(); } break; default: break; } return true; } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); OnColorChangedListener listenr = new OnColorChangedListener() { @Override public void colorChanged(int color) { mListener.colorChanged(color); dismiss(); } }; requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(new ColorPickerView(getContext(), listenr, mInitialColor)); ColorDrawable colorDrawable = new ColorDrawable(); colorDrawable.setColor(Color.BLACK); getWindow().setBackgroundDrawable(colorDrawable); getWindow().setAttributes(new LayoutParams(COLOR_DIALOG_WIDTH,COLOR_DIALOG_HEIGHT, 0,0,0)); } } import cn.eoe.superflashlight.ColorPickerDialog.OnColorChangedListener; import cn.eoe.superflashlight.widget.HideTextView; import android.graphics.Color; import android.os.Bundle; import android.view.View; public class ColorLight extends Bulb implements OnColorChangedListener{ protected int mCurrentColorLight = Color.RED; protected HideTextView mHideTextViewColorLight; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHideTextViewColorLight = (HideTextView)findViewById(R.id.textview_hide_color_light); } @Override public void colorChanged(int color) { mUIColorLight.setBackgroundColor(color); mCurrentColorLight = color; } public void onClick_ShowColorPicker(View view) { ColorPickerDialog dialog=new ColorPickerDialog(this, this, Color.RED); dialog.show(); } } 报了这么一条错误: ![图片说明](https://img-ask.csdn.net/upload/201511/07/1446891363_636502.png) 哪位大神怎么改啊???????????????

在一个自定义的对话框中如何使用一个 list view?

我想在对话框中使用listview,我已经在xml文件中设置了listview,但是我不熟悉怎么使用它(我想用string array填充listview中的值)。 main java: package custom.dialouge.list; import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; public class CustomDialougeListTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Context mContext = this; final Context context = this; Button button; button = (Button) findViewById(R.id.button01); // add button listener button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // custom dialog final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.list); dialog.setTitle("List"); // set the custom dialog components - text, image and button TextView text = (TextView) dialog.findViewById(R.id.TextView01); text.setText("Test"); Button dialogButton = (Button) dialog.findViewById(R.id.Button01); // if button is clicked, close the custom dialog dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }); } } custom dialouge .xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:text="Back" /> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="TextView" /> <ListView android:id="@+id/listview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/Button01" android:layout_alignParentLeft="true" android:layout_below="@+id/TextView01" > </ListView> </RelativeLayout> 在一个自定义的对话框中如何使用一个list?

自定义单选列表对话框单选后item值传递问题

我自定义了一个单选列表的对话框,想要选择一行数据后点击确定按钮再对这行数据进行相应操作, 但是我发现我现在的实现是不论点击哪行传进去的itemPosition都是最初默认的0; 相应部分代码见下: ``` //自定义Dialog public class CustomDialog extends Dialog { public CustomDialog(Context context) { super(context); } public CustomDialog(Context context, int theme) { super(context, theme); } public static class Builder { private Context context; private String title; private String positiveButtonText; private String negativeButtonText; private View contentView; private ArrayList<String> mListItem; private BaseAdapter mAdapter; private int mClickedDialogEntryIndex; private DialogInterface.OnClickListener positiveButtonClickListener; private DialogInterface.OnClickListener negativeButtonClickListener; public Builder(Context context) { this.context = context; } /** * Set the Dialog title from String * * @param title * @return */ public Builder setTitle(String title) { this.title = title; return this; } public Builder setContentView(View v) { this.contentView = v; return this; } public Builder setPositiveButton(String positiveButtonText, DialogInterface.OnClickListener listener) { this.positiveButtonText = positiveButtonText; this.positiveButtonClickListener = listener; return this; } public Builder setNegativeButton(int negativeButtonText, DialogInterface.OnClickListener listener) { this.negativeButtonText = (String) context .getText(negativeButtonText); this.negativeButtonClickListener = listener; return this; } public Builder setNegativeButton(String negativeButtonText, DialogInterface.OnClickListener listener) { this.negativeButtonText = negativeButtonText; this.negativeButtonClickListener = listener; return this; } public ArrayList<String> getItems() { return mListItem; } public Builder setItems(ArrayList<String> mListItem) { this.mListItem = mListItem; return this; } public Builder setSingleChoiceItems(ArrayList<String> mPairedDevicesList, int checkedItem, final OnClickListener listener) { this.mListItem = mPairedDevicesList; this.positiveButtonClickListener = listener; this.mClickedDialogEntryIndex = checkedItem; return this; } public Builder setSingleChoiceItems(BaseAdapter adapter, int checkedItem, final OnClickListener listener) { this.mAdapter = adapter; this.positiveButtonClickListener = listener; this.mClickedDialogEntryIndex = checkedItem; return this; } public CustomDialog create() { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // instantiate the dialog with the custom Theme final CustomDialog dialog = new CustomDialog(context,R.style.Dialog); View layout = inflater.inflate(R.layout.dialog_normal_layout, null); dialog.addContentView(layout, new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); /*if(mListItem == null){ throw new RuntimeException("Entries should not be empty"); }*/ if(mAdapter == null){ throw new RuntimeException("Entries should not be empty"); } ListView lvListItem = (ListView) layout.findViewById(R.id.lvListItem); lvListItem.setAdapter(mAdapter); //lvListItem.setAdapter(new ArrayAdapter(context, R.layout.simple_list_item_single_choice, R.id.text1, mListItem)); lvListItem.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lvListItem.setItemChecked(mClickedDialogEntryIndex, true); lvListItem.setSelection(mClickedDialogEntryIndex); // set the cancel button if (negativeButtonText != null) { ((Button) layout.findViewById(R.id.cancelBtn)) .setText(negativeButtonText); if (negativeButtonClickListener != null) { ((Button) layout.findViewById(R.id.cancelBtn)) .setOnClickListener(new View.OnClickListener() { public void onClick(View v) { negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE); } }); }else{ ((Button) layout.findViewById(R.id.cancelBtn)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub dialog.dismiss(); } }); } } else { // if no confirm button just set the visibility to GONE layout.findViewById(R.id.cancelBtn).setVisibility( View.GONE); } if(positiveButtonText != null){ ((Button) layout.findViewById(R.id.connectBtn)) .setText(positiveButtonText); if (positiveButtonClickListener != null) { ((Button) layout.findViewById(R.id.connectBtn)) .setOnClickListener(new View.OnClickListener() { public void onClick(View v) { positiveButtonClickListener.onClick(dialog, mClickedDialogEntryIndex); } }); }else{ ((Button) layout.findViewById(R.id.connectBtn)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub dialog.dismiss(); } }); } }else { // if no confirm button just set the visibility to GONE layout.findViewById(R.id.connectBtn).setVisibility( View.GONE); } if (contentView != null) { // if no message set // add the contentView to the dialog body ((LinearLayout) layout.findViewById(R.id.content)) .removeAllViews(); ((LinearLayout) layout.findViewById(R.id.content)).addView( contentView, new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); } dialog.setContentView(layout); return dialog; } } } ``` ``` //调用自定义dialog final CustomDialog myDialog = new CustomDialog.Builder(getActivity()) .setTitle(getString(R.string.btdialog_title)) .setPositiveButton(getString(R.string.connect), btnListener) .setNegativeButton(getString(R.string.cancel), null) .setSingleChoiceItems(btAdapter, -1, choiceListener) .create(); myDialog.show(); ``` 其中choiceListener的实现 ``` private class ChoiceOnClickListener implements DialogInterface.OnClickListener{ private int which = 0; public void onClick(DialogInterface dialogInteface, int which){ this.which = which; } public int getWhich(){ return which; } } final ChoiceOnClickListener choiceListener = new ChoiceOnClickListener(); ``` 这里就是不管选择列表中的哪一行,那个我想要的which值一直都是初始的0,为什么呢?

surfaceview自定义组件利用(Context context,AttributeSet attrs)还想传递其他参数

android中利用自定义组件,我想将一个surfaceview作为组件,写到layout中,surfaceview利用(Context context,AttributeSet attrs)构造函数之后,但是,我想将调用它的activity当做参数传进来,我使用了puzzleActivity=(PuzzleActivity)context转化,发现不行,那我该怎么做? 还有,我原本利用setcontentview(),将surfaceview的实例,写进去,surfaceview中原本调用 的图片可以正常显示,但是,一旦将此surfaceview作为自定义组件,利用layout显示时,就会出现空指针的错误,只可以将图片改为几k大小,才可以,这怎么办?

如何自定义WebApi授权验证中context.SetError错误返回格式

在使用MVC WebApi的授权发放GrantResourceOwnerCredentials时候 如何获得自定义返回错误 而不是 context.SetError的默认格式 context.SetError 显示的是 {"error":""}这种 我想要自定义的 比如 {"errorCode":0,"errorMessage":"错误提示内容"}

将surfaceview自定义组件利用(Context context,AttributeSet attrs)还想传递其他参数

android中利用自定义组件,我想将一个surfaceview作为组件,写到layout中,surfaceview利用(Context context,AttributeSet attrs)构造函数之后,但是,我想将调用它的activity当做参数传进来,我使用了puzzleActivity=(PuzzleActivity)context转化,发现不行,那我该怎么做? 还有,我原本利用setcontentview(),将surfaceview的实例,写进去,surfaceview中原本调用 的图片可以正常显示,但是,一旦将此surfaceview作为自定义组件,利用layout显示时,就会出现空指针的错误,只可以将图片改为几k大小,才可以,这怎么办?

android context 空指针 问题

LoginDialog l=new LoginDialog(); l.LoginDialog2(M.this); 我写了个LoginDialog类 如下 结果 老是 报错 public class LoginDialog extends Activity implements OnClickListener { private Context mcontext=null; public void LoginDialog2 (Context context) { this.mcontext = context; LayoutInflater layoutInflater = LayoutInflater.from(context); View longinDialogView = layoutInflater.inflate(MResource.getIdByName(getApplication(), "layout", "logindialog"), null); //获取布局中的控件 EditText mUserName = (EditText)longinDialogView.findViewById( MResource.getIdByName(getApplication(), "id", "edit_username")); EditText mPassword = (EditText)longinDialogView.findViewById( MResource.getIdByName(getApplication(), "id", "edit_password")); //创建一个AlertDialog对话框 AlertDialog longinDialog = new AlertDialog.Builder(context) .setTitle("登录框") .setView(longinDialogView) //加载自定义的对话框式样 .setPositiveButton("确定", this) .setNeutralButton("取消", this) .create(); longinDialog.show(); } @Override public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } } 错误提示 java.lang.NullPointerException

Android自定义View,空指针?

private void drawScale(Canvas canvas) { canvas.save(); canvas.translate(getWidth() / 2 ,getHeight() / 2); canvas.rotate(-133); dialPaint.setColor(Color.parseColor("#3CB7EA")); for (int i = 0; i < (temperature - minTemp)* angleRate;i++) { canvas.drawLine(0,-dialRadius,0,-dialRadius + scaleHeight,dialPaint); canvas.rotate(4.5f); } canvas.rotate(90); dialPaint.setColor(Color.parseColor("#E37364")); for (int i = 0; i < (temperature - minTemp) * angleRate; i++) { canvas.drawLine(0, -dialRadius, 0,-dialRadius + scaleHeight,dialPaint); } canvas.restore(); } 07-12 15:20:16.438 3814-3814/com.huawei.tempcontrolview E/AndroidRuntime: FATAL EXCEPTION: main Process: com.huawei.tempcontrolview, PID: 3814 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Paint.setColor(int)' on a null object reference at com.huawei.tempcontrolview.TempControlView.drawScale(TempControlView.java:168) at com.huawei.tempcontrolview.TempControlView.onDraw(TempControlView.java:151)

使用recyclerView更新数据时程序崩溃

我在编写“添加好友”模块时,根据用户输入的用户名,从服务器获取到了相应信息,但将该数据载入recyclerView更新时程序却崩溃了。接下来是我的代码,以及错误日志。求助大家,小白一只,挣扎了一星期也没找到问题所在。 此为主活动部分:思路是获取输入框的用户名,进入Bmob数据库查询。我调试的时候看到用户是成功查询到的。 public class FriendAdd extends AppCompatActivity { private Button searchUser; private EditText newFriendName; private List<Friend> newFriendList=new ArrayList<>(); private RecyclerView recyclerView; private StrangerAdapter adapter; private LinearLayoutManager layoutManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_friend); searchUser = (Button) findViewById(R.id.addFriend_button_fingNewFriend); newFriendName = (EditText) findViewById(R.id.addFriend_editText_inputFriendName); recyclerView=(RecyclerView)findViewById(R.id.addFriend_recyclerView); adapter =new StrangerAdapter(); layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); searchUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String strangerName=newFriendName.getText().toString(); if(strangerName.isEmpty()){ createDialog("用户名为空","请输入您所查找用户的用户名"); }else{ BmobQuery<User> query = new BmobQuery<User>(); query.addWhereEqualTo("trueName", strangerName); query.findObjects(new FindListener<User>() { @Override public void done(List<User> object, BmobException e) { if(e==null){ for (User gameScore : object) { //获得信息 Friend newFriend=new Friend(gameScore.gettureName(),gameScore.getdepartment()); newFriendList.add(newFriend); } adapter.setDatas(newFriendList); adapter.notifyDataSetChanged(); }else{ createDialog("查询用户失败",e.getMessage()+e.getErrorCode()); } } }); } } }); } private void createDialog(String title, String msg) { AlertDialog.Builder b=new AlertDialog.Builder(this); b.setMessage(msg); b.setTitle(title); b.setNegativeButton("重试", new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog,int which){ dialog.dismiss(); } }); b.create().show(); } } 以下为recyclerView的数据适配器代码: public class StrangerAdapter extends RecyclerView.Adapter<StrangerAdapter.ViewHolder> { private List<Friend> stranger=new ArrayList<>(); static class ViewHolder extends RecyclerView.ViewHolder{ ImageView friendImage; TextView friendName; TextView friendDepartment; public ViewHolder(View view){ super(view); friendImage=(ImageView)view.findViewById(R.id.friendSearch_image_head); friendName=(TextView)view.findViewById(R.id.friendSearch_textView_userName); friendDepartment=(TextView)view.findViewById(R.id.friendSearch_textView_department); } } public StrangerAdapter() { }; public StrangerAdapter(List<Friend> friendList){ stranger=friendList; } public ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){ View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.friend_list_item,parent,false); ViewHolder holder=new ViewHolder(view); return holder; } public void onBindViewHolder(ViewHolder holder,int position){ Friend friend=stranger.get(position); holder.friendImage.setImageResource(friend.getImageId()); holder.friendName.setText(friend.getName()); holder.friendDepartment.setText(friend.getLocation()); } public int getItemCount(){ return stranger.size(); } public void setDatas(List<Friend> list) { stranger.clear(); if (null != list) { stranger.addAll(list); } } } 以下是崩溃后输出的错误日志 04-23 15:28:24.143 16212-16212/com.example.schoolpet E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.schoolpet, PID: 16212 java.lang.ExceptionInInitializerError at java.lang.Class.newInstance(Native Method) at android.app.Instrumentation.newActivity(Instrumentation.java:1070) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2349) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2511) at android.app.ActivityThread.access$900(ActivityThread.java:165) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:5621) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context cn.bmob.v3.BmobWrapper.getApplicationContext()' on a null object reference at cn.bmob.v3.Bmob.Code(Bmob.java:117) at cn.bmob.v3.Bmob.getApplicationContext(Bmob.java:129) at cn.bmob.v3.b.The.<init>(SPUtil.java:28) at cn.bmob.v3.BmobUser.getCurrentUser(BmobUser.java:871) at com.example.schoolpet.PetPage.<clinit>(PetPage.java:59) at java.lang.Class.newInstance(Native Method)  at android.app.Instrumentation.newActivity(Instrumentation.java:1070)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2349)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2511)  at android.app.ActivityThread.access$900(ActivityThread.java:165)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:150)  at android.app.ActivityThread.main(ActivityThread.java:5621)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) 

Recyclerview嵌套recyclerview的深坑,我坐在Recyclerview这个坑里很久了,仰望天空希望能把我拉上去。

Recyclerview嵌套recyclerview的深坑,对于一个新手来说怎么也上不去,特来邀请键盘中的高手高高手,拉拉我; ## 第一个Recyclerview布局: ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/area_LinearLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="true" android:focusableInTouchMode="true" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:background="@drawable/drawable_black_one" android:orientation="horizontal" android:layout_margin="3dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_gravity="center" android:text="" android:textColor="@drawable/drawable_white_pure" android:lines="1" android:layout_weight="1"/> <TextView android:layout_width="1dp" android:layout_height="30dp" android:layout_gravity="center" android:layout_margin="5dp" android:background="@color/whiteness" /> <TextView android:id="@+id/peers_location_TextView" android:layout_width="70dp" android:layout_height="40dp" android:layout_marginLeft="5sp" android:layout_marginRight="10dp" android:ellipsize="end" android:gravity="center" android:text="" android:textColor="@color/whiteness" android:textSize="14sp" android:lines="1" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="3dp" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:layout_width="20dp" android:layout_height="20dp" android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:layout_marginTop="0dp" android:layout_marginEnd="10dp" android:scaleType="fitStart" android:src="@drawable/location" /> </RelativeLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:background="@drawable/drawable_black_one" android:layout_gravity="center" android:focusable="true" android:focusableInTouchMode="true" android:layout_margin="3dp"> <EditText android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_margin="1dp" android:background="@color/text_white" android:hint="行业人员" android:textSize="13dp" android:gravity="center" android:lines="1" android:layout_weight="1"/> <TextView android:layout_width="50dp" android:layout_height="wrap_content" android:text="搜索" android:textSize="14dp" android:layout_marginLeft="14dp" android:layout_gravity="center" android:textColor="@color/whiteness" android:layout_margin="5dp" android:gravity="center"/> </LinearLayout> <android.support.v7.widget.RecyclerView android:id="@+id/user_info_layout" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> ``` ## 在第一个Recycleview的item里面嵌套了第二个Recyclerview不知道这样对不对? ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/portrait" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/user_portrait" android:layout_width="50dp" android:layout_height="50dp" android:layout_margin="5dp" android:src="@drawable/em_default_avatar" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="20dp" android:layout_marginTop="5dp" android:gravity="clip_horizontal"> <TextView android:id="@+id/user_industry" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/dialog_circular_whiteness" android:ellipsize="end" android:gravity="center" android:text="建筑" android:textColor="@color/colorPrimary" android:textSize="14sp" android:textStyle="bold" /> <TextView android:id="@+id/user_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginLeft="5dp" android:background="@drawable/dialog_circular_whiteness" android:ellipsize="end" android:gravity="center" android:text="努力改变自己" android:textColor="#323232" android:textSize="10sp" android:textStyle="bold" /> <TextView android:id="@+id/name_voip" android:layout_width="20dp" android:layout_height="wrap_content" android:layout_gravity="center" android:ellipsize="end" android:gravity="center" android:text="voip" android:textColor="@color/text_pink" android:textSize="7sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="35dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="努力改变自己" android:textSize="12dp" /> </LinearLayout> </LinearLayout> <RelativeLayout android:layout_width="60dp" android:layout_height="match_parent" android:gravity="center"> <TextView android:id="@+id/user_location" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:background="@drawable/dialog_circular_whiteness" android:text="" android:textSize="12dp" android:textStyle="bold" /> </RelativeLayout> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> **<!-- 导入RecyclerView-->** <android.support.v7.widget.RecyclerView android:id="@+id/user_peesr_info" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="10dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:text="访问:10000人" android:textSize="8dp" /> </LinearLayout> </LinearLayout> </LinearLayout> ``` ## 第一个Recyclerview的适配器: ``` public class Home_RecyclerView_Adapter extends RecyclerView.Adapter<Home_RecyclerView_Adapter.myViewHodler> { private Context context; private LinkedList<Home_list_get_set> LinkedList; public LinkedList<User_Recruitment_get_set> mLinkedList; public Home_list_get_set mHome_list_get_set; //创建构造函数 public Home_RecyclerView_Adapter(Context context, LinkedList<Home_list_get_set> industrytitlegetsetList) { //将传递过来的数据,赋值给本地变量 this.context = context;//上下文 this.LinkedList = industrytitlegetsetList;//实体类数据ArrayList } /** * 创建viewhodler,相当于listview中getview中的创建view和viewhodler * * @param parent * @param viewType * @return */ @Override public myViewHodler onCreateViewHolder(ViewGroup parent, int viewType) { RecyclerView user_peesr_info;//自定义recyclerveiw的适配器 //创建自定义布局 // View itemView = View.inflate(context, R.layout.peers_list_item, null);//用这个布局item宽高无效 // myViewHodler itemView = new myViewHodler(LayoutInflater.from(context).inflate(R.layout.peers_list_item, parent, false)); View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.peers_list_item, parent, false); user_peesr_info = view.findViewById (R.id.user_peesr_info); //给嵌套的RecyclerView设置适配器 User_Recruitment_Adapter user_recruitment_adapter = new User_Recruitment_Adapter (context,mLinkedList); user_peesr_info.setAdapter (user_recruitment_adapter); user_peesr_info.setLayoutManager (new LinearLayoutManager (context, LinearLayoutManager.HORIZONTAL, false)); //给嵌套的RecyclerView设置item的分割线 user_peesr_info.addItemDecoration (new DividerItemDecoration (context, DividerItemDecoration.HORIZONTAL)); return new myViewHodler(view); // return itemView; } /** * 绑定数据,数据与view绑定 * * @param holder * @param position */ @SuppressLint("ClickableViewAccessibility") @Override public void onBindViewHolder(myViewHodler holder, int position) { //根据点击位置绑定数据 mHome_list_get_set = LinkedList.get(position); // holder.mItemGoodsImg; holder.user_name.setText(mHome_list_get_set.getUser_name()); holder.user_industry.setText(mHome_list_get_set.getUser_work()); // holder.user_portrait.setImageDrawable (data.getHead_portait ());//改为下面Glide获取图上 Glide.with(context) .load(mHome_list_get_set.getHead_portait ())//图片信息 .apply(RequestOptions.bitmapTransform(new CircleCrop ()))//设置圆形 .into(holder.user_portrait);//设置到那个部位 holder.name_voip.setText(mHome_list_get_set.getUser_Vip()); holder.user_location.setText(mHome_list_get_set.getUser_location()); } /** * 得到总条数 * * @return */ @Override public int getItemCount() { // return LinkedList.size(); return LinkedList == null ? 0 : LinkedList.size(); } //自定义viewhodler class myViewHodler extends RecyclerView.ViewHolder { private ImageView user_portrait; private TextView user_name; private TextView user_industry; private TextView name_voip; private TextView user_location; public RecyclerView user_peesr_info;//自定义recyclerveiw的适配器 public myViewHodler(View itemView) { super(itemView); user_peesr_info = itemView.findViewById (R.id.user_peesr_info); user_portrait = itemView.findViewById(R.id.user_portrait); user_name = itemView.findViewById(R.id.user_name); user_industry = itemView.findViewById(R.id.user_industry); name_voip = itemView.findViewById(R.id.name_voip); user_location = itemView.findViewById(R.id.user_location); user_portrait.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //可以选择直接在本位置直接写业务处理 //Toast.makeText(context,"点击了xxx",Toast.LENGTH_SHORT).show(); //此处回传点击监听事件 if (onItemClickListener != null) { onItemClickListener.OnItemClick(v, LinkedList.get(getLayoutPosition())); } } }); } public View getItemView() { return itemView; } } /** * 设置item的监听事件的接口 */ public interface OnItemClickListener { /** * 接口中的点击每一项的实现方法 * * @param view 点击的item的视图 * @param data 点击的item的数据 */ public void OnItemClick(View view, Home_list_get_set data); } //需要外部访问,所以需要设置set方法,方便调用 private OnItemClickListener onItemClickListener; public void setOnItemClickListener(OnItemClickListener onItemClickListener) { this.onItemClickListener = onItemClickListener; } ``` ## 第二个Recyclerview的适配器: ``` public class User_Recruitment_Adapter extends RecyclerView.Adapter<User_Recruitment_Adapter.myViewHodler> { public LinkedList<User_Recruitment_get_set> m_LinkedList; private Context context; public User_Recruitment_get_set mUser_Recruitment_get_set; //创建构造函数 public User_Recruitment_Adapter(Context context, LinkedList<User_Recruitment_get_set> mLinkedList) { //将传递过来的数据,赋值给本地变量 this.context = context;//上下文 this.m_LinkedList = mLinkedList; } @NonNull @Override public myViewHodler onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.user_peers_recruitment_item, viewGroup, false); return new myViewHodler(view); } @Override public void onBindViewHolder(@NonNull myViewHodler myViewHodler, int i) { mUser_Recruitment_get_set = m_LinkedList.get(i); myViewHodler.recruitment.setText (mUser_Recruitment_get_set.getRecruitment ()); } @Override public int getItemCount() { return m_LinkedList == null ? 0 : m_LinkedList.size(); } public class myViewHodler extends RecyclerView.ViewHolder { private TextView recruitment; public myViewHodler(@NonNull View itemView) { super (itemView); recruitment = itemView.findViewById(R.id.recruitment); } } } ``` ## 现问题是嵌套里面的Recyclerview无显示内容?我该如何写?

自定义控件不显示问题

``` 自定义属性 <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="Bottom"> <attr name="oneText" format="string"/> <attr name="twoText" format="string"/> <attr name="threeText" format="string"/> <attr name="oneTextSize" format="dimension"/> <attr name="twoTextSize" format="dimension"/> <attr name="ThreeTextSize" format="dimension"/> <attr name="oneTextColor" format="color"/> <attr name="twoTextColor" format="color"/> <attr name="ThreeTextColor" format="color"/> <attr name="oneImageIcon" format="reference|color"/> <attr name="twoImageIcon" format="reference|color"/> <attr name="threeImageIcon" format="reference|color"/> <attr name="backColor" format="color"/> </declare-styleable> </resources> ``` 引用 ``` <com.example.myappzdybottom.zdy.MyBottom android:layout_width="fill_parent" android:layout_height="200dp" mybottom:oneText="第一个" mybottom:twoText="第二个" mybottom:oneTextSize="8sp" mybottom:oneTextColor="#FFFFFF" mybottom:twoTextColor="#FF0000" ></com.example.myappzdybottom.zdy.MyBottom> ``` 自定义view ``` public class MyBottom extends RelativeLayout{ //定义自定义属性对应的控件 private TextView textview01,textview02,textview03; private ImageView imageview01,imageview02,imageview03; private String text01,text02,text03; private Drawable drawable01,drawable02,drawable03; private int textColor01,textColor02,textColor03,backColor; private float textSize; private LinearLayout ll01,ll02,ll03; public MyBottom(Context context, AttributeSet attrs) { super(context, attrs); //建立映射 TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attrs, R.styleable.Bottom); text01=obtainStyledAttributes.getString(R.styleable.Bottom_oneText); text02=obtainStyledAttributes.getString(R.styleable.Bottom_twoText); text03=obtainStyledAttributes.getString(R.styleable.Bottom_threeText); drawable01=obtainStyledAttributes.getDrawable(R.styleable.Bottom_oneImageIcon); drawable02=obtainStyledAttributes.getDrawable(R.styleable.Bottom_twoImageIcon); drawable03=obtainStyledAttributes.getDrawable(R.styleable.Bottom_threeImageIcon); textColor01=obtainStyledAttributes.getColor(R.styleable.Bottom_oneTextColor, 0); textColor02=obtainStyledAttributes.getColor(R.styleable.Bottom_twoTextColor, 0); textColor03=obtainStyledAttributes.getColor(R.styleable.Bottom_ThreeTextColor, 0); backColor=obtainStyledAttributes.getColor(R.styleable.Bottom_backColor, 0); textSize=obtainStyledAttributes.getDimension(R.styleable.Bottom_oneTextSize, 0); obtainStyledAttributes.recycle(); //实例化控件 textview01=new TextView(context); textview02=new TextView(context); textview03=new TextView(context); imageview01=new ImageView(context); imageview02=new ImageView(context); imageview03=new ImageView(context); textview01.setText(text01); textview02.setText(text02); textview03.setText(text03); textview01.setTextColor(textColor01); textview02.setTextColor(textColor01); textview03.setTextColor(textColor01); textview01.setTextSize(textSize); textview02.setTextSize(textSize); textview03.setTextSize(textSize); imageview01.setBackground(drawable01); imageview02.setBackground(drawable02); imageview03.setBackground(drawable03); LayoutParams llParams=new LayoutParams(80, LayoutParams.MATCH_PARENT ); llParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE); LayoutParams llParams02=new LayoutParams(150, LayoutParams.MATCH_PARENT); llParams02.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE); ll01=new LinearLayout(context); ll02=new LinearLayout(context); ll03=new LinearLayout(context); ll01.setBackgroundColor(Color.BLACK); ll02.setBackgroundColor(Color.BLUE); /* ll01.setOrientation(LinearLayout.VERTICAL); ll02.setOrientation(LinearLayout.VERTICAL); ll03.setOrientation(LinearLayout.VERTICAL); LayoutParams textParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams imageParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); textview01.setGravity(Gravity.CENTER_HORIZONTAL);*/ LayoutParams textParams=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ll01.addView(textview01, textParams); //ll01.addView(imageview01, imageParams); ll02.addView(textview02,textParams); //ll02.addView(imageview02, imageParams); /*ll03.addView(textview03, imageParams); ll03.addView(imageview03, imageParams);*/ addView(ll01,llParams); addView(ll02,llParams02); } ``` 想在父view中添加三个字view为LinearLayout 这个可以 但是在子view中在添加TextView 就不行了 TextView 就是不显示 找不到原因,也没报错,请大神指教!!! 万分感谢!!!!

Android TV开发,ScrollView嵌套RecyclerView滑动问题

我用的是FocusLayout来让有焦点的控件有个边框, 结果当RecyclerView由下滑动到第一行条目的时候,因为ScrollView还没有到最上面的顶点, 所以还能再往上滑动一次,这个时候FocusLayout还是会绘制一个边框,然后那里没有控件. 请教大佬帮忙解决下. FocusLayout的代码如下,这个是用来绘制边框的. ```public class FocusLayout extends RelativeLayout implements ViewTreeObserver.OnGlobalFocusChangeListener { private LayoutParams mFocusLayoutParams; private View mFocusView; public FocusLayout(Context context) { super(context); init(context); } public FocusLayout(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public FocusLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); } private void init(Context context) { this.mFocusLayoutParams = new LayoutParams(0, 0); this.mFocusView = new View(context); this.mFocusView.setBackgroundResource(R.drawable.default_focus); // this.mFocusView.setBackgroundResource(R.drawable.focus); // this.mFocusView.setBackgroundColor(getResources().getColor(R.color.test)); this.addView(this.mFocusView, this.mFocusLayoutParams); } public void show(){ mFocusView.setVisibility(View.VISIBLE); } public void unShow(){ mFocusView.setVisibility(View.INVISIBLE); } @Override public void onGlobalFocusChanged(View oldFocus, View newFocus) { Rect viewRect = new Rect(); if (newFocus==null)return; newFocus.getGlobalVisibleRect(viewRect); correctLocation(viewRect); this.setFocusLocation( viewRect.left - this.mFocusView.getPaddingLeft(), viewRect.top - this.mFocusView.getPaddingTop(), viewRect.right + this.mFocusView.getPaddingRight(), viewRect.bottom + this.mFocusView.getPaddingBottom()); } /** * 由于getGlobalVisibleRect获取的位置是相对于全屏的,所以需要减去FocusLayout本身的左与上距离,变成相对于FocusLayout的 * @param rect */ private void correctLocation(Rect rect) { Rect layoutRect = new Rect(); this.getGlobalVisibleRect(layoutRect); rect.left -= layoutRect.left; rect.right -= layoutRect.left; rect.top -= layoutRect.top; rect.bottom -= layoutRect.top; } /** * 设置焦点view的位置,计算焦点框的大小 * * @param left * @param top * @param right * @param bottom */ protected void setFocusLocation(int left, int top, int right, int bottom) { int width = right - left; int height = bottom - top; this.mFocusLayoutParams.width = width; this.mFocusLayoutParams.height = height; this.mFocusLayoutParams.leftMargin = left; this.mFocusLayoutParams.topMargin = top; this.mFocusView.layout(left, top, right, bottom); } } ```

RecyclerView初始化时加载了全部item,导致打开页面卡顿问题

一个选择城市的页面,打开页面时就初始化了全部item,之后怎么滑动也不会再调用onBindViewHolder方法。下面是适配器代码,求解谢谢! ``` public class SelectCityRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private Context mContext; private final int TYPE_LETTER = 0; private final int TYPE_CHINESE = 1; private final int TYPE_HEADER = 2; private SelectCityContract.OnSelectCityListener mListener; private String mLetters[] = {"#", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; private int mLetterPos[] = new int[27]; SelectCityRvAdapter(Context context){ mContext = context; mListener = (SelectCityContract.OnSelectCityListener) context; getAllLetterPos(); } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view = null; if(viewType == TYPE_LETTER){ view = LayoutInflater.from(mContext).inflate(R.layout.item_select_city_letter,parent, false); return new ViewHolderLetter(view); }else if(viewType == TYPE_CHINESE){ view = LayoutInflater.from(mContext).inflate(R.layout.item_select_city_chinese,parent, false); return new ViewHolderCity(view); } return null; } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) { if(holder instanceof ViewHolderLetter){ ((ViewHolderLetter)holder).textView.setText(City.citys[position]); for(int i=0;i<mLetterPos.length;i++){ if(mLetterPos[i] == position){ mListener.onScrollLetter(i); } } }else if(holder instanceof ViewHolderCity){ ((ViewHolderCity)holder).textView.setText(City.citys[position]); ((ViewHolderCity)holder).textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mListener.onSelect(City.citys[position]); } }); } KLog.i("aaa","第"+position+"项"); } @Override public int getItemCount() { return City.citys.length; } @Override public int getItemViewType(int position) { Pattern pattern = Pattern.compile("^[A-Z]"); if (pattern.matcher(City.citys[position]).matches()){ return TYPE_LETTER; }else{ return TYPE_CHINESE; } } public int[] getLetterPos(){ return mLetterPos; } private void getAllLetterPos(){ ThreadPoolUtils.getInstance().execute(new Runnable() { @Override public void run() { for(int n=0;n<mLetters.length;n++){ boolean exits = false; for(int i=0;i<City.citys.length;i++){ if(City.citys[i].equals(mLetters[n])){ mLetterPos[n] = i; exits = true; break; } } if(!exits){ if(n == 0){ mLetterPos[0] = 0; }else{ mLetterPos[n] = mLetterPos[n - 1]; } } } } }); } public class ViewHolderCity extends RecyclerView.ViewHolder{ TextView textView; public ViewHolderCity(View itemView) { super(itemView); textView = itemView.findViewById(R.id.textView); } } public class ViewHolderLetter extends RecyclerView.ViewHolder{ TextView textView; public ViewHolderLetter(View itemView) { super(itemView); textView = itemView.findViewById(R.id.textView); } } }![图片说明](https://img-ask.csdn.net/upload/201901/29/1548743089_581308.png) ```

RecyclerView内存在多个EditText时,长按弹不出系统的复制/粘贴/全选等选择

在仿微博发布头条文章功能的时候出现了这么一个问题。 ``` public class NewsReleaseAdapter3 extends RecyclerView.Adapter { private Context context; private List<EditDetailBean> list; public NewsReleaseAdapter3(Context context, List<EditDetailBean> list) { this.context = context; this.list = list; } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { EditText editText = new EditText(context); editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); return new TxtViewHolder(editText); } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof TxtViewHolder) { setTxtView((TxtViewHolder) holder, position); } } private void setTxtView(TxtViewHolder holder, final int position) { final EditDetailBean bean = getItem(position); if (bean != null) { _ holder.contentEt.setText("123321123");_ } } private class TxtViewHolder extends RecyclerView.ViewHolder { EditText contentEt; private TxtViewHolder(View itemView) { super(itemView); contentEt = (EditText) itemView; // contentEt = (EditText) itemView.findViewById(R.id.contentEt); } } @Override public int getItemViewType(int position) { return super.getItemViewType(position); } @Override public int getItemCount() { return list.size(); } private EditDetailBean getItem(int position) { return list.get(position); } ``` 只要添加了“holder.contentEt.setText("123321123");”经过滑动,就会出现EditText长按没有震动反馈,也没有弹出菜单。但是能进入onLongClickListener. 跪求大神

安卓对话框中显示Toast问题

``` Builder builder=new Builder(this); builder.setTitle("单选框"); builder.setMessage("有本事你选"); builder.setPositiveButton("确定", new OnClickListener(){ public void onClick(DialogInterface arg0, int arg1) { Toast.makeText(this, "你选了确定", 0).show(); } }); ``` Toast.makeText(this, "你选了确定", 0).show(); 这句话把getApplicationContext()替换成this 会报错: The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new DialogInterface.OnClickListener(){}, String, int) 为什么不能用this?

安卓自定义View中AttributeSet问题

我在github上看到一个比较炫酷的仪表盘型进度条,然后就下下来玩,可是我遇到一个问题, 看如下代码: ``` public class DashedCircularProgress extends RelativeLayout { private ExternalCirclePainter externalCirclePainter;//外部圆 private InternalCirclePainter internalCirclePainter;//内部圆 private ProgressPainter progressPainter; private IconPainter iconPainter;//圆圈上面有图片 private Bitmap image; // Interpolator 被用来修饰动画效果,定义动画的变化率,可以使存在的动画效果accelerated(加速), // decelerated(减速),repeated(重复),bounced(弹跳)等。 private Interpolator interpolator = new AccelerateDecelerateInterpolator(); private int externalColor = Color.WHITE; private int internalBaseColor = Color.YELLOW; private int progressColor = Color.WHITE; private float min = 0; private float last = min; private float max = 100; private ValueAnimator valueAnimator; private OnValueChangeListener valueChangeListener; private float value ; private int duration = 1000; private int padingTop = 22; private int heightNormalittation = 10; private int progressStrokeWidth = 48; public DashedCircularProgress(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public DashedCircularProgress(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs); } /**中间还有些代码,就省略没有贴上来*/ public void setValue(float value) { this.value = value; if (value <= max || value >= min) { animateValue(); } } } ``` 我现在想在我的活动中调用这个类中的setValue()方法,可是这个构造方法里面有个 AttributeSet attrs,于是我就不懂这个到底该怎么传入这个参数,这个参数应该设置一些 什么东西,各位前辈指点一下吧,感谢!!!

自定义view使用动画的问题

最近在学习自定义view相关的东西,想实现一个画圆的动画,但是始终没有效果,代码如下: ``` public class AnimatorView extends View { private static final String TAG = "AnimatorView"; private Paint mPaint; private RectF mArcRectF; private ObjectAnimator mProgressAnim; private int mProgress = 0; public AnimatorView(Context context) { this(context, null); } public AnimatorView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public AnimatorView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); initAnimator(); } private void init() { if(mPaint == null) mPaint = new Paint(); setLayerType(View.LAYER_TYPE_SOFTWARE, null); mPaint.setAntiAlias(true); mPaint.setStyle(Paint.Style.STROKE); mPaint.setColor(Color.RED); mPaint.setStrokeWidth(16); } private void initAnimator() { mProgressAnim = ObjectAnimator.ofInt(this, "progress", 0, 360); mProgressAnim.setDuration(5000); mProgressAnim.setInterpolator(null); } public int getProgress() { return mProgress; } public void setProgress(int progress) { mProgress = progress; invalidate(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec); int height = MeasureSpec.getSize(heightMeasureSpec); int centerX = width / 2; int centerY = height / 2; int offset = Math.min(centerX, centerY) / 2; mArcRectF = new RectF(centerX - offset, centerY - offset, centerX + offset, centerY + offset); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Log.d(TAG, "onDraw() ---> mProgress=" + mProgress); canvas.drawArc(mArcRectF, 90, mProgress, false, mPaint); mProgressAnim.start(); } } ``` 我的想法是通过mProgress来逐渐的将圆弧扩大,但实际效果是这个值一直为0,这个属性动画还是没搞明白

easyui弹出对话框在更改宽度时位置出现偏移

``` easyui弹出对话框在更改宽度时位置出现偏移 <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.7.2.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/default/easyui.css"> <!--引入CSS样式--> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/icon.css"> <!--Icon引入--> <script type="text/javascript" src="${pageContext.request.contextPath}/locale/easyui-lang-zh_CN.js"></script> <!--汉化--> <script type="text/javascript"> $(function(){ $("#d1").dialog({ title:"fdfd", width:200, height:300, collapsible:true, buttons:[{text:"确定",handler:function(){ //begin $("#d1").panel({width:900}); // $("#d1").dialog({width:900});当使用这个时不会,为什么 //end $.messager.alert("你点击了确定将立即进行宽度的更改"); }},{text:"取消",handler:function(){ $.messager.alert("你点击了取消"); }}] }); }); </script> </head> <body> <div id="d1"></div> </body> 我是新手,麻烦用通俗易懂的话语告诉我,谢谢 ```

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

ArrayList源码分析(入门篇)

ArrayList源码分析 前言: 写这篇博客的主要原因是,在我上一次参加千牵科技Java实习生面试时,有被面试官问到ArrayList为什么查找的速度较快,插入和删除的速度较慢?当时我回答得不好,很大的一部分原因是因为我没有阅读过ArrayList源码,虽然最后收到Offer了,但我拒绝了,打算寒假学得再深入些再广泛些,下学期开学后再去投递其他更好的公司。为了更加深入理解ArrayList,也为

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

玩转springboot启动banner定义所得

最近接手了一个springboot项目,不是不熟悉这个框架,启动时打印的信息吸引了我。 这不是我熟悉的常用springboot的打印信息啊,我打开自己的项目: 还真是的,不用默认的感觉也挺高大上的。一时兴起,就去研究了一下源代码,还正是有些收获,稍后我会总结一下。正常情况下做为一个老程序员,是不会对这种小儿科感兴趣的,不就是一个控制台打印嘛。哈哈! 于是出于最初的好奇,研究了项目的源代码。看到

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

立即提问
相关内容推荐