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

问题描述

我有两个活动,A和B.在A,它有一个的ListView 按钮。在B,它具有的ImageView EDITTEXT 。现在我想实现的是从B文本返回的ListView A.

活动A

 查看索赔= inflater.inflate(R.layout.receipt_text,集装箱,FALSE);
     listV =(ListView控件)claims.findViewById(R.id.listView);
  的String []状态= {索赔的类型:+名字,金额+导致};     适配器=新ArrayAdapter<串GT;(这一点,R.layout.claims,地位);
     listV.setAdapter(适配器);  返回索赔;
    }  @覆盖
    公共无效的onActivityResult(INT申请code,INT结果code,意图数据){//选自B接收文本        开关(要求code){
                情况下0:
                    结果= data.getStringExtra(文字);
                    名称= data.getStringExtra(一);
                    说明= data.getStringExtra(C);                    打破;
}

活动B

  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();        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);
                        完();
                    }
                });        公共无效addListenerOnButton(){
        的ImageButton =(的ImageButton)findViewById(R.id.imageButton);
        imageButton.setOnClickListener(新View.OnClickListener(){            @覆盖
            公共无效的onClick(查看为arg0){
                Global.img = NULL;
                意图I =新意图(Project1.this,C.class);
                startActivityForResult(I,PROJECT_REQUEST_ code);
            }        });    }    公共无效的onActivityResult(INT申请code,INT结果code,意图数据)
    {//从C接收
        如果(要求code == PROJECT_REQUEST_ code){
            如果(数据= NULL&放大器;!&安培; data.hasExtra(文本)){
                C = data.getStringExtra(文字);
                txt1.setText(C);
                viewImage.setImageBitmap(Global.img);
            }
        }
        否则,如果(要求code == CAMERA_REQUEST_ code)
        {        }
    }}

receipt_text.xml

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT
    机器人:方向=垂直>    <的TextView的android:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT机器人:填充=10dp
        机器人:文字=@字符串/文本的android:TEXTSIZE =20SP/>    <的TextView
      机器人:ID =@ + ID / TextView的
      机器人:layout_width =match_parent
      机器人:layout_height =match_parent>
    < / TextView的>    < ListView的机器人:ID =@ + ID / ListView1的机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT/>< / LinearLayout中>

claims.xml

 < android.support.v4.widget.DrawerLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / drawer_layout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>< /android.support.v4.widget.DrawerLayout>

错误

解决方案

The constructor for ArrayAdapter is wrong.

adapter=new ArrayAdapter<String>(this,R.layout.claims,c);

Instead of passing an int into the ArrayAdapter constructor, creating a List and pass it in. Later add the data you get from Activity B to the list.

List<String> list = new ArrayList<>();
adapter=new ArrayAdapter<String>(this, R.layout.claims, list);

When you get the data back from ActivityB, do this

    String data = Integer.toString(c);
list.add(data);
adapter.notifyDataSetChanged();

这篇关于的EditText没有返回到的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 20:37