簡體   English   中英

單擊列表視圖中的項目時顯示圖像

[英]display image when clicked on the item in listview

我正在使用listview ...我嘗試在列表上單擊itemclick時打開圖像,並且正在另一個活動中...但是它不起作用...如果發現您知道的話,請幫助我...謝謝......

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


// Find the ListView resource. 
mainListView = (ListView) findViewById( R.id.mainListView );
mainListView.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> mainListView, View view, int pos,
            long id) {

        //Object obj = getFilesDir().getPath();
        //String value= obj.toString();

        Intent intent= new         Intent(SimpleListViewActivity.this,Nextclass.class);
        final String root = Environment.getExternalStorageDirectory().getAbsolutePath();
        intent.setData(Uri.parse(root + "/mnt/sdcard/dcim/100andro/koala_copy.jpg"));
        startActivity(intent);
    }

    private ArrayAdapter<String> getListAdapter() {
        // TODO Auto-generated method stub
        return null; 
    }

我的main.xml是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:id="@+id/mainListView">
</ListView>

</LinearLayout>

我們還需要查看NextClass的代碼,因為這就是接收您正在啟動的Intent的原因。 它應該是Activity的子類。 然后在其onCreateonResume調用getIntent() ,檢查該意圖是否具有所需的額外內容/數據,然后將圖像加載到ImageView或其他中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM