gpt4 book ai didi

java - 初学者 Android : ListView to affect the next class

转载 作者:行者123 更新时间:2023-12-02 07:48:13 26 4
gpt4 key购买 nike

我是一名初学者程序员,所以请耐心等待。我正在尝试创建一个应用程序,其中 ListView 中的项目会影响下一个 Activity 中将显示的内容。到目前为止,我有列表 Activity :

public class Primary extends ListActivity{
private static final String[] items = {"Item1", "Item2", "Item3", "item4", "Item5"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));

TextView heading =(TextView)findViewById(R.id.listViewHeading);
heading.setText("Primary");
}

public void onListItemClick(ListView parent, View v, int position, long id){

}

对于第二个 Activity ,我有这个:

public class ImageActivity extends Activity{
TextView heading;
ImageView image;
TextView text;
public static final String[] headings={"heading 1", "heading 2", "heading 3", "heading 4", "heading 5",};


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_activity);

heading = (TextView)findViewById(R.id.adHeading);
image = (ImageView)findViewById(R.id.adImage);
text =(TextView)findViewById(R.id.adText);

addInfo();
}

private void addInfo() {
heading.setText(headings[x]);
image.setImageResource(images[x]);
text.setText(text[x]);

}

如何才能使标题、图像和文本根据 ListView 中选择的项目而变化?

最佳答案

在 ListView Activity 中。

Intent i = new Intent(this, ImageActivity.class);
i.putExtra("data", data);
startActivity(i);

下一个 Acitivity onCreate() 方法。

final String data = getIntent().getStringExtra("data");

关于java - 初学者 Android : ListView to affect the next class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10560343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com