【发布时间】:2012-01-13 13:25:09
【问题描述】:
抱歉,伙计们无法正常工作,在 onclick 事件期间发生错误。我想将选定的文本传递回启动活动。我是新手,所以请放轻松:)
public class selectTee extends ListActivity{
String[] tees_list;
String value = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tees_list = getResources().getStringArray(R.array.tees_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_view, tees_list));
final ListView teelist = getListView();
teelist.setChoiceMode(1);
teelist.setTextFilterEnabled(false);
teelist.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> teeAdapter, View arg1, int selectedInt, long selectedLong) {
//Error occurs during the onclick event
Intent data = new Intent();
data.putExtra(value, selectedInt);
setResult(RESULT_OK, data);
finish();
}
});
}
}
好的,我让它工作了,我更改了以下代码:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == request_Code) {
if (resultCode == RESULT_OK){
Button revisedButton = (Button) findViewById(R.id.button1);
String btext = data.getData().toString();
revisedButton.setText((CharSequence) btext);
}
}
}
以及返回活动
public void onItemClick(AdapterView<?> teeAdapter, View arg1, int selectedInt, long selectedLong) {
String selection =((TextView) arg1).getText().toString();
System.out.println(selection);
Intent data = new Intent();
Uri uri = Uri.parse(selection);
System.out.println(uri);
data.setData(uri);
setResult(RESULT_OK, data);
finish();
}
});
【问题讨论】:
-
错误是什么。日志会有所帮助。
-
12-05 17:47:40.781: ERROR/AndroidRuntime(1310): java.lang.RuntimeException: 传递结果失败 ResultInfo{who=null, request=1, result=-1, data= Intent { cmp=com.prophecysoftware.GolfProphecy/.SetupNewCourse (has extras) }} 到活动 {com.prophecysoftware.GolfProphecy/com.prophecysoftware.GolfProphecy.SetupNewCourse}: android.content.res.Resources$NotFoundException: String resource ID # 0xffffffff