我有兩個片段之一與列表視圖和其他與textview,我想當一個項目被選中它的文本是用來設置另一個textview上的文本片段並顯示這個其他片段。使用列表查看選定的項目在一個片段上顯示其他片段上的文本
所以我已經設置onItemClickListener在列表視圖(lv)像這樣;
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v1,
int pos, long arg3) {
String hh = lv.getItemAtPosition(pos).toString().toLowerCase();
int resd = getResources().getIdentifier(hh, "raw", getPackageName());
InputStream isd = getResources().openRawResource(resd);
BufferedReader brd = new BufferedReader(new InputStreamReader(isd));
String lined;
String entireFiled = "";
try {
while((lined = brd.readLine()) != null) {
entireFiled += (lined + "\n");
}
}
catch (Exception e) {
Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
TextView output1= (TextView) findViewById(R.id.fp);
output1.setText(entireFiled);
Family frag5 = new Family();
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction().replace(R.id.fl, frag5).addToBackStack(null);
ft.commit();
}
});
另一個片段叫做Family,它的textview是output1。當我運行它時,我在textview行得到null異常。那麼我該怎麼做?謝謝你
我用[從這個類似的問題]的答案(http://stackoverflow.com/questions/22568339 /傳遞數據從一個片段到另一個) – vinstar