2011-03-02 6 views
0

私はボタンを持っています。クリックするとリストビューに画像&(静的テキスト)が表示されます。これどうやってするの?Androidの画像とテキストのリストビュー

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

私はボタンをクリックすると、私はreplyview.But私はlistview(画像とテキスト)を同じページに表示する必要があります。 – sanjay

答えて

0
  • uはGetViewメソッドで膨張rをこのレイアウトファイルの "R.layout.listview" は、1つのImageViewのを追加します。

  • 次に、2番目のtextview text2の代わりにビューホルダーにimageviewを追加します。

    class ViewHolder { 
        TextView text; 
        ImageView IM2; 
    } 
    
  • getViewメソッドでこれを行いますholder.text2.setText(country[position]);の代わりに

    holder.IM2 = (ImageView) convertView 
          .findViewById(R.id.ImageView02); 
    
  • を、あなたのImageViewの上の背景画像を設定します。

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

ありがとうございました。