安卓:做一些动作后填充的ListView元素 [英] Android: Do some action AFTER filling ListView elements
本文介绍了安卓:做一些动作后填充的ListView元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有ListView和附加页脚的活动。我创建我的自定义适配器的ListView填充。之后我填它,我需要做一些动作。
这是我的活动的code部分:
I have an activity with listview and attached footer. I created my custom adapter for filling ListView. After I filled it I need to do some actions. This is my activity's code part:
public class MainActivity extends ListActivity {
final public String NO_USERS_IN_DB = "No users yet, please add some...";
DBAdapter db = new DBAdapter(this);
Activity activity = MainActivity.this;
private static final Pattern PATTERN = Pattern.compile(": *([^|]+)");
private static final int REQUEST_LOAD = 0;
boolean rewrite;
boolean userSelected = false;
final public int REQUEST_SAVE = 1;
boolean showAvatars;
boolean settingsGot = false;
int backgroundColor;
int titleColor;
int buttonBackgroundColor;
int buttonTextColor;
public class MyCustomAdapter extends ArrayAdapter<String> {
public MyCustomAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//return super.getView(position, convertView, parent);
if(!settingsGot){
getSettings();
settingsGot = true;
}
String[] users = getUsers();
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.main, parent, false);
TextView label=(TextView)row.findViewById(R.id.label);
label.setText(users[position]);
if(showAvatars){
ImageView icon=(ImageView)row.findViewById(R.id.icon);
byte[] bb = getAvatar(users[position]);
if(bb != null && bb.length != 0){
icon.setImageBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length));
icon.setVisibility(View.VISIBLE);
}
}
return row;
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
db.open();
String[] users = db.getUsersList();
boolean showList = true;
if (users[0].equals("NOUSERSINTHEBASE")){
users[0] = NO_USERS_IN_DB;
}
if (showList){
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView listView = getListView();
listView.addFooterView(footer);
this.setListAdapter(new MyCustomAdapter(this,
R.layout.main, users));
}else{
setContentView(R.layout.footer);
}
db.close();
}
所以,我的方法需要方法 getView
完成工作后做一些动作。我应该在哪里把我的 doSomeMoreActionsAfterGetView()
?
So, method I need to do some actions after method getView
done its work. Where should I place my doSomeMoreActionsAfterGetView()
?
推荐答案
setListAdapter后,你可以改变它...
After setListAdapter you can change it...
这篇关于安卓:做一些动作后填充的ListView元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文