我创建了一个adpter,它将一些消息文本设置为textView和一个简单的按钮, 但仍无法看到该权限的GUI。
我没有任何错误,但在此之前仍然无法看到屏幕上的附件。
adpter的代码:
public class messageDisplayAdapter extends ArrayAdapter {
public Context mContext;
private String message;
public AlertDialog alertDialog;
private int id;
public messageDisplayAdapter(Context context, int textViewResourceId, String message) {
super(context, textViewResourceId);
mContext = context;
id = textViewResourceId;
this.message=message;
}
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater =LayoutInflater.from(this.mContext);
row = inflater.inflate(R.layout.message, parent, false);
}
// final int itemPosition = position;
TextView Item = (TextView) row.findViewById(R.id.textView );
Button btn = (Button) row.findViewById(R.id.ButtonOk);
btn.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
// Toast.makeText(getApplicationContext(), "Toast from button"+ //Colors[itemPosition], Toast.LENGTH_SHORT).show();
}
});
return row;
}
显示版权的类:
protected void onPostExecute(String result) {
try {
Dialog.dismiss();
Intent intent = new Intent(this.context, Class.forName(this.newActivity));
context.startActivity(intent);
//finish();}
} catch (ClassNotFoundException ex) {
/* messageDisplayAdapter messageDisplayAdapter = new messageDisplayAdapter(this.context, R.layout.message, "error on loading");
messageDisplayAdapter.showMessage();
*/
ListView lv =new ListView(this.context);
lv.setTextFilterEnabled(true);
messageDisplayAdapter listAdapter= new messageDisplayAdapter(this.context,R.layout.message,"error on loading");
// listAdpter.setListAdapter(listAdapter); // on test
lv.setAdapter(listAdapter); // on test
}
}
感谢您的帮助!
答案 0 :(得分:0)
尝试在getView中将setText添加到textView,如下所示
public class messageDisplayAdapter extends ArrayAdapter {
public Context mContext;
private String message;
public AlertDialog alertDialog;
private int id;
public messageDisplayAdapter(Context context, int textViewResourceId, String message) {
super(context, textViewResourceId);
mContext = context;
id = textViewResourceId;
this.message=message;
}
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater =LayoutInflater.from(this.mContext);
row = inflater.inflate(R.layout.message, parent, false);
}
// final int itemPosition = position;
TextView Item = (TextView) row.findViewById(R.id.textView );
Item.setText(message); // Try This line
Button btn = (Button) row.findViewById(R.id.ButtonOk);
btn.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
// Toast.makeText(getApplicationContext(), "Toast from button"+ //Colors[itemPosition], Toast.LENGTH_SHORT).show();
}
});
return row;
}
同时请尝试遵循命名约定。