本文介绍了编辑ListView控件值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个活动,A,B和C.The活动的流程是从A到B那么C.从C,所有的图像和值将返回到B然后A.所有返回的价值和形象将是加载的ListView A.

的ListView 是点击,一旦点击,就会意图到B做一些版本。但现在的问题是,当我编辑在B中的文本值并返回到A,我得到更新老一新的列表,而不是。
什么是错在这里?任何人都可以帮忙吗?

活动ç

 公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.image_fit_screen);
        selectImage();
        B =(ImageView的)findViewById(R.id.imageView3);
        T =(EditText上)findViewById(R.id.editText38);
        取消=(按钮)findViewById(R.id.button15);
        OK =(按钮)findViewById(R.id.button16);        cancel.setOnClickListener(新View.OnClickListener()
        {
            公共无效的onClick(查看为arg0){
                完();
            }
        });        ok.setOnClickListener(新View.OnClickListener()
        {//返回到B
            公共无效的onClick(查看arg0中)
            {
                意图returnIntent =新的Intent();
                。文字= t.getText()的toString();
                b.setDrawingCacheEnabled(真);
                b.measure(View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED),
                        View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED));
                b.layout(0,0,b.getMeasuredWidth(),b.getMeasuredHeight());
                b.buildDrawingCache(真);
                returnIntent.putExtra(文字,文本);
                如果(b.getDrawingCache()!= NULL){
                    位图的位图= Bitmap.createBitmap(b.getDrawingCache());
                    如果(位图== NULL){
                        Log.e(TAG,getDrawingCache()==空);
                    }
                    Global.img =位图;
                }
                的setResult(Activity.RESULT_OK,returnIntent);
                完();
            }
        });
    }

活动B

 的ImageButton ImageButton的;
    ImageView的viewImage;
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.project);
        TXT =(EditText上)findViewById(R.id.editText36);
        TXT1 =(的TextView)findViewById(R.id.textView57);
        按钮B =(按钮)findViewById(R.id.button17);
        addListenerOnButton();
        viewImage =(ImageView的)findViewById(R.id.imageView2);        如果(getIntent()。getExtras()!= NULL){//如果已经从一个值通
            最后弦乐金额= getIntent()getExtras()的getString(结果)。;
            最后弦乐说明1 = getIntent()getExtras()的getString(说明)。;            txt1.setText(说明1);
            txt.setText(金额);
        }                b.setOnClickListener(新View.OnClickListener(){//回归A
                    公共无效的onClick(查看为arg0){
                        意图returnIntent =新的Intent();
                        A =项目;
                        。文字= txt.getText()的toString(); //量
                        returnIntent.putExtra(文字,文本);
                        returnIntent.putExtra(一,一);
                        returnIntent.putExtra(C,C);
                        的setResult(Activity.RESULT_OK,returnIntent);
                        完();
                    }
                });
                viewImage.setImageBitmap(Global.img);                }    公共无效addListenerOnButton(){
         的ImageButton =(的ImageButton)findViewById(R.id.imageButton);
         imageButton.setOnClickListener(新View.OnClickListener(){            @覆盖
            公共无效的onClick(查看为arg0){
                Global.img = NULL;
                意图I =新意图(B.this,C.class);
                startActivityForResult(I,PROJECT_REQUEST_ code);
            }        });    }    公共无效的onActivityResult(INT申请code,INT结果code,意图数据)
    {
        如果(要求code == PROJECT_REQUEST_ code){//收到FOMÇ
            如果(数据= NULL&放大器;!&安培; data.hasExtra(文本)){
                C = data.getStringExtra(文字);
                txt1.setText(C);
                viewImage.setImageBitmap(Global.img); //从C图像可以在这里显示
            }
        }
        否则,如果(要求code == CAMERA_REQUEST_ code)
        {        }
    }}

活动A

 公共类Claims1扩展片段{    ListView的listV;
    字符串描述;
    字符串结果=;
    字符串名称;
    只要= 0;
    的TextView℃;
    ImageView的伏;
  ArrayAdapter<串GT;适配器;
    ArrayList的<串GT; m_listItems =新的ArrayList<串GT;();
    字符串文本;  公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
                             捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        捆绑包= this.getArguments();
        setHasOptionsMenu(真);
        查看索赔= inflater.inflate(R.layout.receipt_text,集装箱,FALSE);
        V =(ImageView的)claims.findViewById(R.id.imageView4);
        listV =(ListView控件)claims.findViewById(R.id.listView1);
        android.support.v7.app.ActionBar myActionBar =((AppCompatActivity)getActivity())getSupportActionBar();
        myActionBar.setHomeButtonEnabled(真);
        ImageView的ImageView的=新ImageView的(myActionBar.getThemedContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        imageView.setImageResource(R.mipmap.create);
        适配器=新ArrayAdapter<串GT;(getActivity(),R.layout.claims,R.id.textView1,m_listItems);        android.support.v7.app.ActionBar.LayoutParams的LayoutParams =新android.support.v7.app.ActionBar.LayoutParams(
                android.support.v7.app.ActionBar.LayoutParams.WRAP_CONTENT,
                android.support.v7.app.ActionBar.LayoutParams.WRAP_CONTENT,Gravity.RIGHT
                | Gravity.CENTER_VERTICAL); //在操作栏图标
        layoutParams.rightMargin = 40;
        imageView.setLayoutParams(的LayoutParams);
        myActionBar.setCustomView(ImageView的);        listV.setOnItemClickListener(新AdapterView.OnItemClickListener(){
            公共无效onItemClick(适配器视图<>的ListView,观景,
                                    INT位置,长的id){
              如果(name.equals(项目)){
                    意向意图=新意图(Claims1.this.getActivity(),B.class);
                    intent.putExtra(位图,真正的);
                    intent.putExtra(名,名);
                    intent.putExtra(结果,结果);
                    startActivityForResult(意向,0);
                }            }
        });
        返回索赔;
    }    @覆盖
    公共无效onCreateOptionsMenu(菜单菜单,MenuInflater气筒){
        inflater.inflate(R.menu.my_menu,菜单);
        super.onCreateOptionsMenu(菜单,充气器);    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        开关(item.getItemId()){
            案例R.id.create1:
                AlertDialogRadio();
                返回true;
        }
        回报(super.onOptionsItemSelected(项目));
    }
    公共无效AlertDialogRadio(){
        最终的CharSequence [] = ClaimsModel {B,汽油};        AlertDialog.Builder alt_bld =新AlertDialog.Builder(getActivity());
        alt_bld.setTitle(选择一个类);
        alt_bld.setSingleChoiceItems(ClaimsModel,-1,新DialogInterface
                .OnClickListener(){            公共无效的onClick(DialogInterface对话,诠释项){
                如果(项目== 0){
                    意向意图=新意图(getActivity()getApplicationContext(),B.class。);
                    startActivityForResult(意向,0);
                }否则如果(项目== 1){
                    意向意图=新意图(getActivity()getApplicationContext(),Petrol.class。);
                    startActivityForResult(意向,1);
                }
                dialog.dismiss();            }
        });
        AlertDialog警报= alt_bld.create();
        alert.show();
    }    @覆盖
    公共无效的onActivityResult(INT申请code,INT结果code,意图数据){        开关(要求code){
                情况下0:
                    结果= data.getStringExtra(文字);
                    名称= data.getStringExtra(一);
                    说明= data.getStringExtra(C);
                    如=的Long.parseLong(结果);
                    Log.d(第一,结果是:+结果);
                    文本=+姓名++RM+结果+;
                    m_listItems.add(文本);
                    adapter.notifyDataSetChanged();
                    listV.setAdapter(适配器);                    打破;                情况1:
                    结果= data.getStringExtra(文字);
                    名称= data.getStringExtra(一);
                    说明= data.getStringExtra(C);
                    如果(Global.img!= NULL){
                        v.setImageBitmap(Global.img);
                    }
                    如=的Long.parseLong(结果);
                    c.setText(+姓名+------+RM+结果);
                    打破;
        }    }

编辑

在A增加一个全局变量 - 私人诠释mClickedPosition ;
添加 mClickedPosition =位置; 在OnItemClick

然后

  @覆盖
公共无效的onActivityResult(INT申请code,INT结果code,意图数据){    开关(要求code){
            情况下0:
                结果= data.getStringExtra(文字);
                名称= data.getStringExtra(一);
                说明= data.getStringExtra(C);
                如=的Long.parseLong(结果);
                Log.d(第一,结果是:+结果);
                文本=+姓名++RM+结果+;
                m_listItems.set(mClickedPosition,文本);
                adapter.notifyDataSetChanged();
                listV.setAdapter(适配器);                打破;

 m_listItems.set(mClickedPosition,Text);
解决方案

Try edit your code like this:

case 0:
    result = data.getStringExtra("text");
    name = data.getStringExtra("a");
    description = data.getStringExtra("c");
    as = Long.parseLong(result);
    Log.d("FIRST", "result:"+result);
    Text="  "+name+"                                  "+"RM"+result+"";
    if (m_listItems.size() == 0) {
        m_listItems.add(Text);
    } else {
        m_listItems.set(mClickedPosition,Text);
    }
    adapter.notifyDataSetChanged();
    listV.setAdapter(adapter);

    break;

这篇关于编辑ListView控件值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 22:35