我寫了下面的代碼,但我確信我在方法onItemClick()中做了錯誤() 我的列表視圖顯示正確,點擊時另一項活動打開我想只顯示在新的活動 圖像所以需要從你們我想在另一個活動中打開一個圖像,當點擊列表視圖中的項目時
MainActivity
public class MainActivity extends ActionBarActivity {
String[] days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday" };
int[] images = { R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher };
int[] images1 = { R.drawable.image01, R.drawable.image02,
R.drawable.image03, R.drawable.image04, R.drawable.image05,
R.drawable.image06, R.drawable.image07 };
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.listView1);
ArjAdapter adapter = new ArjAdapter(getBaseContext(), days, images);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
File imgfile = new File("");
if (imgfile.exists()) {
String myBitmap = imgfile.getAbsolutePath();
Intent intent = new Intent(MainActivity.this,
ImageActivity.class);
intent.setType("image/*");
intent.putExtra("img", "images1");
startActivity(intent);
}
}
});
在上述方法的一些幫助,我不知道該文件的對象中包括的內容,這種方法我看到了某處,但我不確定它裏面包含什麼,所以留下了空白ķ從你們
ImageActivity,其中我想顯示圖像
public class ImageActivity extends Activity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.images);
Bitmap myBitmap = BitmapFactory.decodeFile(getIntent().getStringExtra(
"img"));
ImageView iv = (ImageView) findViewById(R.id.imageView2);
iv.setImageBitmap(myBitmap);
}
任何建議,歡迎
你的意思是你要顯示在images1 []陣列右點擊的圖像? – 2014-10-29 12:11:10
7項在列表視圖和7圖像在我images1 [],當點擊各自的項目時,相應的圖片應顯示在我的ImageActivity,是 – 2014-10-29 12:13:32
我發表答案只是試圖讓我知道會發生什麼 – 2014-10-29 12:21:10