Android:填写ListView元素后执行一些操作

时间:2011-11-21 07:39:02

标签: android

我有listview和附加页脚的活动。我创建了自定义适配器来填充ListView。在我填写之后我需要做一些动作。 这是我活动的代码部分:

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()

1 个答案:

答案 0 :(得分:1)

在setListAdapter之后你可以改变它......