2011-03-02 8 views
0

버튼이있어서 그것을 클릭하면리스트 뷰를 이미지 & 텍스트 (정적 텍스트)와 함께 표시하고 싶습니다. 어떻게해야합니까?안드로이드에서 이미지와 텍스트의리스트보기

My code.. 
public class category extends ListActivity { 
    Button category; 
    TextView selection; 
    private static final String[] country = { "Iceland", "India", "Indonesia", 
     "Iran", "Iraq", "Ireland", "Israel", "Italy", "Laos", "Latvia", 
     "Lebanon", "Lesotho ", "Liberia", "Libya", "Lithuania", 
     "Luxembourg" }; 
     private static final String[] curr = { "ISK", "INR", "IDR", "IRR", "IQD", 
     "EUR", "ILS", "EUR", "LAK", "LVL", "LBP", "LSL ", "LRD", "LYD", 
     "LTL ", "EUR" 

     }; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.category); 

     category=(Button)findViewById(R.id.category); 



     class EfficientAdapter extends BaseAdapter { 
      private LayoutInflater mInflater; 

      public EfficientAdapter(OnClickListener onClickListener) { 
      mInflater = LayoutInflater.from((Context) onClickListener); 

      } 

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

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

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

      public View getView(int position, View convertView, ViewGroup parent) { 
      ViewHolder holder; 
      if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.listview, null); 
      holder = new ViewHolder(); 
      holder.text = (TextView) convertView 
      .findViewById(R.id.TextView01); 
      holder.text2 = (TextView) convertView 
      .findViewById(R.id.TextView02); 

      convertView.setTag(holder); 
      } else { 
      holder = (ViewHolder) convertView.getTag(); 
      } 

      holder.text.setText(curr[position]); 
      holder.text2.setText(country[position]); 

      return convertView; 
      } 

      class ViewHolder { 
      TextView text; 
      TextView text2; 
      } 
      } 
     category.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 

       ListView l1 = (ListView) findViewById(R.id.ListView); 
       l1.setAdapter(new EfficientAdapter(this)); 

      } 

     }); 

    } 

} 
+0

단추만으로 구성된 활동을 시작하십시오. 단추를 누르는 것은 의도를 사용하여이 범주 활동을 호출합니다. 이게 니가 원하는거야? –

+0

ur reply를 보내 주셔서 감사합니다.하지만 버튼을 클릭하면 같은 페이지에 listview (이미지 및 텍스트)를 표시해야합니다. – sanjay

답변

0
  • 유의 getView 방법에서 팽창 r에 레이아웃 파일 "R.layout.listview를"한 번 이미지 뷰를 추가한다.

  • 이제 이미지 뷰를 두 번째 텍스트 뷰 text2 대신보기 소유자에 추가하십시오.

    class ViewHolder { 
        TextView text; 
        ImageView IM2; 
    } 
    
  • 은의 getView에서이 작업을 수행 : holder.text2.setText(country[position]); 대신에

    holder.IM2 = (ImageView) convertView 
          .findViewById(R.id.ImageView02); 
    
  • , 당신의 이미지 뷰에 배경 이미지를 설정합니다.

ex. holder.IM2.setBackgroundDrawable(getResources().getDrawable(R.drawable.vimage));

감사합니다.

관련 문제