我在页面中有一个列表视图,并且在 ListView 内单击一个按钮,我想用新的数据集重新加载页面。
package com.examples.listzones;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MyActivity extends Activity implements
AdapterView.OnItemClickListener, View.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView list = new ListView(this);
setContentView(list);
String[] items = { "Tom", "Sally", "Bill", "John", "Santiago", "Isabella" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.review, R.id.textView1, items) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
View text = row.findViewById(R.id.seemore);
text.setTag(position);
text.setOnClickListener(MyActivity.this);
return row;
}
};
list.setAdapter(adapter);
list.setOnItemClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.seemore:
// RELOAD THE PAGE WITH NEW SET OF DATA
break;
default:
break;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(this, "Item Click " + position, Toast.LENGTH_SHORT).show();
}
}
在 OnClick 内部,我想用新数据集加载页面。