好了,做个简短的总结。应用程序打开一个listView (由字符串数组填充),当您点击列表中的一个项目时,它会将您带到另一个listView (由字符串数组填充),其中包含与您点击的第一个项目相关联的项目。在第二个listView中,我想点击一个项目,让它显示一个textView,其中包含来自另一个字符串数组的相关项目。到目前为止,我已经使前两个listViews正常工作,但是不能使textView工作。我已经为这件事苦苦思索了两天,现在变得非常沮丧。你能帮帮忙吗!
下面是我的字符串xml文件:
<string-array name="topics">
<item>Idioms</item>
<item>Travel</item>
<item>Small Talk</item>
<item>Tips</item>
<item>App Data</item>
</string-array>
<string-array name="idioms">
<item>Cash Chow</item>
<item>No Spring chicken</item>
</string-array>
<string-array name="travel">
<item>Asking for Change</item>
<item>Bus and Train Schedule</item>
</string-array>
<string-array name="idioms_description">
<item>A cash cow is a blah blah blah</item>
<item>No spring chicken means blah blah blah</item>
</string-array>
<string-array name="travel_description">
<item>This is a test for Asking for change</item>
<item>This is a test for Bus and train schedules</item>
</string-array>这是我的getIntent和我应该setText的地方。我把它留空是因为到目前为止我尝试过的所有东西都失败了,我只是不知道如何从选择的数组中获得正确的字符串。
public class DetailLanguagePoints extends Activity{
private int position;
private TextView mLanguagePoint;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_view);
mLanguagePoint = (TextView) findViewById(R.detail.languagepoints);
Bundle extras = getIntent().getExtras();
//int[] arrayIds = new int[]{R.array.idioms, R.array.travel};
position = extras.getInt("listposition");
int[] stringarrayIds = new int[]{R.array.idioms_description, R.array.travel_description};
String[] subTopics = getResources().getStringArray(stringarrayIds[position]);
String description = subTopics[position];
final String TAG = "MyActivity";
Log.d(TAG,description);
mLanguagePoint.setText(description);
}
}我发现了空异常错误的问题所在,我没有在setcontentView()之后调用findViewById()。我这样做了,它解决了问题,现在它可以工作了!感谢所有提供建议的人!!
发布于 2012-04-30 21:56:01
使用此代码mPosition = i.getIntExtra("listposition");而不是此mPosition = i.getIntExtra("listposition", 0);
发布于 2012-04-30 22:00:41
因此,您只想将subTopics设置为ListView?
ListView listView = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, subTopics);
listView.setAdapter(adapter);否则,请张贴你是如何失败的任何logcat错误。
发布于 2012-04-30 22:06:50
您希望在TextView中显示什么内容?这两个子项之间是否有新的一行分隔?如果是这样,那么只需将mLanguagePoint.setText()更改为mLanguagePoint.setText(subTopics[0] + "\n" + subTopics[1])
https://stackoverflow.com/questions/10384787
复制相似问题