【发布时间】:2015-11-16 02:25:32
【问题描述】:
我有两个 Activity,A 和 B。在 A 中,它有一个 listView 和一个 button。在 B 中,它有 imageView 和 editText 。现在我想要实现的是将文本从 B 返回到 listView A。
活动 A
View claims = inflater.inflate(R.layout.receipt_text, container, false);
listV = (ListView) claims.findViewById(R.id.listView);
String [] status ={"Type of Claims :" +name,"Amount :" +result};
adapter=new ArrayAdapter<String>(this,R.layout.claims,status);
listV.setAdapter(adapter);
return claims;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { // receive text from B
switch (requestCode) {
case 0:
result = data.getStringExtra("text");
name = data.getStringExtra("a");
description = data.getStringExtra("c");
break;
}
活动 B
ImageView viewImage;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.project);
txt = (EditText) findViewById(R.id.editText36);
txt1=(TextView)findViewById(R.id.textView57);
Button b = (Button) findViewById(R.id.button17);
addListenerOnButton();
b.setOnClickListener(new View.OnClickListener() { // return to A
public void onClick(View arg0) {
Intent returnIntent = new Intent();
a = "Project";
text = txt.getText().toString(); // amount
returnIntent.putExtra("text", text);
returnIntent.putExtra("a", a);
returnIntent.putExtra("c", c);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
});
public void addListenerOnButton() {
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Global.img=null;
Intent i = new Intent(Project1.this, C.class);
startActivityForResult(i, PROJECT_REQUEST_CODE);
}
});
}
public void onActivityResult(int requestCode,int resultCode, Intent data)
{ // receive from C
if(requestCode==PROJECT_REQUEST_CODE) {
if(data!=null&&data.hasExtra("text")) {
c = data.getStringExtra("text");
txt1.setText(c);
viewImage.setImageBitmap(Global.img);
}
}
else if (requestCode==CAMERA_REQUEST_CODE)
{
}
}
}
receipt_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:padding="10dp"
android:text="@string/text" android:textSize="20sp" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
<ListView android:id="@+id/listView1" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
claims.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
</android.support.v4.widget.DrawerLayout>
错误
11-16 10:57:24.696 30313-30313/com.example.project.project E/AndroidRuntime: FATAL EXCEPTION: main 进程:com.example.project.project,PID:30313 java.lang.IllegalStateException: ArrayAdapter 要求资源 ID 为 TextView
【问题讨论】:
标签: java android listview start-activity