2013-10-05 2 views
0

목록의 항목보기 View.if 첫 번째 항목을 클릭합니다. 내가 activit을 시작하고 일부 이미지를 표시합니다. 두 번째 목록 항목을 클릭하면 다른 활동이 시작되고 일부 활동이 시작됩니다. 이미지 집합입니다. 여기에 목록보기 코드가 있습니다. package com.example.per.app;이미지 어댑터가 포함 된 ListView

public class AlbumListActivity extends Activity { 

    public String[] mListInfo = { "1st Month", "2nd Month", "3rd Month", 
      "4th Month", "5th Month", "6th Month", "7th Month", "8th Month", 
      "9th Month", "10th Month", "11th Month", "12th Month" }; 
    public ListView mList = null; 
    public Intent mLaunch = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.list_album); 
     mList = (ListView) findViewById(R.id.list_view); 
     ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(
       getApplicationContext(), android.R.layout.simple_list_item_1, 
       mListInfo); 
     mList.setAdapter(mAdapter); 
     mList.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
        long arg3) { 

       switch (arg2) { 
       case 0: 
        mLaunch = new Intent(getApplicationContext(),FirstMonthActivity.class); 
        startActivity(mLaunch); 
       } 
      } 

     }); 

    } 
    public class ImageAdapter extends BaseAdapter { 
     private Context mContext; 

     public ImageAdapter(Context c) { 
      mContext = c; 
     } 

     public int getCount() { 
      return mThumbIds.length; 
     } 

     public Object getItem(int position) { 
      return null; 
     } 

     public long getItemId(int position) { 
      return 0; 
     } 

     // create a new ImageView for each item referenced by the Adapter 
     public View getView(int arg0, View arg1, ViewGroup arg2) { 
      ImageView imageView; 
      if (arg1 == null) { // if it's not recycled, initialize some 
           // attributes 
       imageView = new ImageView(mContext); 
       imageView.setLayoutParams(new GridView.LayoutParams(363, 363)); 
       imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
       imageView.setPadding(0, 0, 0, 0); 
      } else { 
       imageView = (ImageView) arg1; 
      } 
      imageView.setImageResource(mThumbIds[arg0]); 
      return imageView; 
     } // references to our images 

     Integer[] mThumbIds = { R.drawable.sample0, R.drawable.sample1, 
       R.drawable.sample2, R.drawable.sample3, R.drawable.sample4, 
       R.drawable.sample5, R.drawable.sample6, R.drawable.sample7, 
       R.drawable.sample8, R.drawable.sample9 }; 
    } 
} 

보기 항목의 이미지 항목 클래스를 유지해야합니까? 목록 항목마다 다른 이미지 집합을 표시하고 싶습니다.

현재 케이스 0 만 추가하고 케이스 1 케이스 2 케이스 3 ... 케이스 12를 추가 할 예정입니다. 따라서 12 개의 activities.in 각 액티비티를 시작해야합니다. 다른 이미지 세트를 표시하고 싶습니다.

답변

1

질문이 명확하지 않습니다. 12 가지 활동을 시작할 필요가 없다고 생각합니다. 하나의 액티비티 만 작성할 수 있으며 목록 항목에서 해당 액티비티를 클릭하면 다음 액티비티에 이미지 세트로 사용될 드로어 블의 int 배열을 전달할 수 있습니다. 여기

는 경우에 당신이 (12) 등의 ArrayList가 필요할 수 있도록이 같은 드로어 블의 일부 ArrayList를 유지할 수 목록 활동에서 당신이 시도 할 수있는 샘플 코드 ....

입니다. 당신이 목록 항목을 클릭하면

ArrayList<Integer> thumb1list = new ArrayList<Integer>(); 
     thumb1list.add(R.drawable.ic_launcher); 
     thumb1list.add(R.drawable.ic_launcher); 
     thumb1list.add(R.drawable.ic_launcher); 

그리고 그 다음, 마지막으로 두 번째 활동이

Intent intent = new Intent(MainActivity.this , Second.class); 
     intent.putIntegerArrayListExtra("key", thumb1list); 
     startActivity(intent); 

처럼 두 번째 활동을 시작이

ArrayList<Integer> Array = getIntent().getExtras().getIntegerArrayList("key"); 
처럼 정수의 위의 ArrayList를 잡을

그러면 이러한 이미지를 Gridview 또는 원하는 어떤 것으로로드 할 수 있습니다.

+0

저는 List에 12 개의 항목이 있습니다. res 폴더에 120 개의 이미지가 있습니다. 각 List 항목에 대해 10 개의 이미지를 표시하고 싶습니다. 어떻게해야합니까? – chait

+0

수정 된 답변보기 및 궁금한 점이 있으면 알려주십시오. – ayon

+0

그래서 내 코드에서 ImageAdaper 클래스를 사용하여 이미지를로드했습니다. 클래스가 필요하지 않으므로 위의 코드를 참조하십시오. – chait

관련 문제