我正在尝试这样做:当用户单击列表项时, Activity 级别会出现一个对话框,然后用户将选择“更新”他的 Activity 级别,然后我想将此值放入 row_data 中,有可能这样做吗?我该怎么做?我尝试过这种方法:
public void onClick(DialogInterface dialog, int which) {
profile_data[4]=new ProfileListItems(R.drawable.arrow_left,Activity_level[which],"ActivityLevel");
但是没用
public class ProfileView extends Activity {
private ListView mList;
private Profile [] profile_data;
private String[] Activity_level;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
profile_data= new Profile[]
{
new Profile("Name",StaticPreferences.getName(this),R.drawable.arrow_left),
new Profile("Age", StaticPreferences.getAge(this),R.drawable.arrow_left) ,
new Profile("Height",StaticPreferences.getHeight(this),R.drawable.arrow_left),
new Profile("Weight", StaticPreferences.getWeight(this),R.drawable.arrow_left),
new Profile("ActivityLevel",StaticPreferences.getActivity(this),R.drawable.arrow_left)
};
ProfileAdapter adapter = new ProfileAdapter(this,R.layout.row,profile_data);
mList=(ListView)findViewById(R.id.profile_list);
View header = (View)getLayoutInflater().inflate(R.layout.header, null);
mList.addHeaderView(header);
mList.setAdapter(adapter);
mList .setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if( position==2)
showHeightDialog();
else if(position==3)
showWeightDialog();
else if(position==4)
showActivityDialog();
}
}
private void showActivityDialog()
{ int j=0;
Activity_level=getResources().getStringArray(R.array.Activity_Level_Array);
AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
localBuilder.setTitle(" choose your Activity Level);
localBuilder.setSingleChoiceItems(Activity_level,j, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
saveActivityLevel(Activity_level[which]); // store the user activity level
profile_data[4]=new Profile("ActivityLevel",Activity_level[which],R.drawable.arrow_left);
showMessage("your activity level updated");
}
});
localBuilder.setPositiveButton("OK", null);
this.Activity_LevelDialog = localBuilder.create();
this.Activity_LevelDialog.show();
}
private void saveActivityLevel(String Activity_level)
{
StaticPreferences.setActivityLevel(this, Activity_level);
}
}
最佳答案
打电话怎么样...
adapter.notifyDataSetChanged();
告诉 View (作为适配器的观察者)重绘。
关于java - 如何设置用户在列表项中输入的新数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9743537/