java - 如何设置用户在列表项中输入的新数据?

标签 java android

我正在尝试这样做:当用户单击列表项时, Activity 级别会出现一个对话框,然后用户将选择“更新”他的 Activity 级别,然后我想将此值放入 row_data 中,有可能这样做吗?我该怎么做?我尝试过这种方法:

 public void onClick(DialogInterface dialog, int which) {
 profile_data[4]=new ProfileListItems(R.drawable.arrow_left,Activity_level[which],"ActivityLevel"); 

但是没用

enter image description here

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/

相关文章:

java - 使用 Kotlin 时 FXML 控件始终为空

android - 在 Android 中创建上下文菜单

javascript - Appcelerator SQLite 替换或更新命令

android - 如何直接在 Android 手机上测试我的应用程序开发?

java - 比较列表中同一对象的两个实例

java - Element.getStyle() 在 GWT 中不返回任何值

java - 我无法计算我的订阅者的Youtube API V3

java - 休息服务: how to produce human readable output using XML + XSLT?

android - 以编程方式访问应用程序通知设置

android - 在 Android 中异步发送 HTTP GET 请求的最佳方式?