我已經有一個名爲SI的活動,帶有GridView,其中包含可讓您在單擊時進入另一活動的單元。我想知道如何得到相同的活動,只是根據哪個意圖啓動它來更改TextView。如何根據哪些意圖啓動它來更改活動內容?
public class SI extends AppCompatActivity {
GridView gridView;
String[] units;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zakladnijednotky);
gridView = (GridView) findViewById(R.id.gridView1);
units = getResources().getStringArray(R.array.units);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, units);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
if (gridView.getItemAtPosition(position).toString().contains("amper")) {
Intent mintent = new Intent(SI.this, MainActivity.class);
startActivity(mintent);
}
else if (gridView.getItemAtPosition(position).toString().contains("kilogram")) {
Intent kilintent = new Intent(SI.this, MainActivity.class);
startActivity(kilintent);
}
else if (gridView.getItemAtPosition(position).toString().contains("metre")) {
Intent metrintent = new Intent(SI.this, MainActivity.class);
startActivity(metrintent);
}
else if (gridView.getItemAtPosition(position).toString().contains("second")) {
Intent mintent = new Intent(SI.this, MainActivity.class);
startActivity(mintent);
}
else if (gridView.getItemAtPosition(position).toString().contains("kelvin")) {
Intent mintent = new Intent(SI.this, MainActivity.class);
startActivity(mintent);
}
else if (gridView.getItemAtPosition(position).toString().contains("candela")) {
Intent mintent = new Intent(SI.this, MainActivity.class);
startActivity(mintent);
}
else if (gridView.getItemAtPosition(position).toString().contains("mol")) {
Intent mintent = new Intent(SI.this, MainActivity.class);
startActivity(mintent);
}
}
});
}
...
}
的可能的複製[我如何從意向o獲得額外的數據[Android的]](http://stackoverflow.com/questions/4233873/how-do-i-get-extra-data-from-intent-on-android) – Gary99