中的另一個類中選定的列表項,這裏是我的類,當我運行它的應用程序崩潰的選擇,並給了我一個空錯誤。我正在設計一個修訂版應用程序,並且正在努力做到這一點,而不必爲涵蓋的每個主題創建一個類,任何幫助都將不勝感激。我怎樣才能獲得訪問Android
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.w3c.dom.Text;
public class TheoryMain extends Activity {
TheoryTopicList ttl;
TextView tv1;
String choice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.theory_layout);
ttl = new TheoryTopicList();
ttl.getChoice();
tv1 = (TextView) findViewById(R.id.theory_tv);
switch(choice){
case("Photo-Electric effect"):
tv1.setText(getString(R.string.photo_electric));
break;
case("Photons and Electrons"):
tv1.setText(getString(R.string.photons_electrons));
break;
case("de Broglie wavelength"):
tv1.setText(getString(R.string.de_broglie));
break;
case("Types of particles"):
tv1.setText(getString(R.string.particles));
break;
case("Interactions"):
tv1.setText(getString(R.string.interactions));
break;
case("Radiation"):
tv1.setText(getString(R.string.radiation));
break;
case("Voltage, Current and Resistance(Ohms law)"):
tv1.setText(getString(R.string.ohms_law));
break;
case("Circuits"):
tv1.setText(getString(R.string.circuits));
break;
case("Power and Efficiency"):
tv1.setText(getString(R.string.power_efficiency));
break;
case("Alternating Current and oscilloscope graphs"):
tv1.setText(getString(R.string.ac_graphs));
break;
case("E.M.F and internal Resistance"):
tv1.setText(getString(R.string.emf_resistance));
break;
}
}
}
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class TheoryTopicList extends ListActivity {
String[] display = {"Photo-Electric effect", "Photons and Electrons", "de Broglie wavelength", "Types of particles",
"Interactions", "Radiation", "Voltage, Current and Resistance(Ohms law)", "Circuits",
"Power and Efficiency","Alternating Current and oscilloscope graphs", "E.M.F and internal Resistance"};
String choice;
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
choice = display[position];
Intent intent = new Intent("com.revisonapp.alec.alevelphysics.THEORYMAIN");
startActivity(intent);
}
public String getChoice(){
return choice;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(TheoryTopicList.this,android.R.layout.simple_list_item_1,display));
}
}
使用'Intent.putExtra'發送''意圖字符串''TheoryMain活動和''TheoryMain活動中使用'getIntent'接收選定的值。請參閱以下文章[將數據從一個活動轉移到另一個活動使用意圖](http://stackoverflow.com/questions/4967740/transfer-data-from-one-activity-to-another-activity-using-intents)可能有幫助 –