2012-05-02 19 views
1

こんにちはすべてGridViewコントロールとのImageButton奇妙な問題

enter image description here

私は問題はグリッドがクリックできない..ですIMAGEBUTTONを使用していた。ここ

..しかし、私場合を次のように私はIMAGEBUTTONとのTextViewを持つカスタムグリッドビューを持っていますここを使用してくださいimageViewそれはうまく動作しますが、UIは適切ではありません。

はここにここに私のアダプタ

package com.tt.cc; 

import java.util.List; 

import android.content.Context; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 

public class SavedConferencesGridAdapter extends ArrayAdapter<String>{ 


    Context mContext; 
    List<String> confernceList; 

    public SavedConferencesGridAdapter(Context context, int textViewResourceId, List<String> confernceList) 
    { 

     super(context,textViewResourceId,confernceList); 
     this.confernceList = confernceList; 
     this.mContext = context; 
     Log.e("TAG", confernceList.size()+""); 
    } 

    int[] picIds = new int[] { R.drawable.newschedule,R.drawable.newexhibitors, 
           R.drawable.newsponsers, R.drawable.newlocation, 
           R.drawable.newfavourites, R.drawable.newreminder,R.drawable.info,R.drawable.info,R.drawable.info,R.drawable.info,R.drawable.info,R.drawable.info }; 


    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return confernceList.size(); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     View v; 



     if(convertView==null){ 
      LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = li.inflate(R.layout.entity, null); 
      TextView tv = (TextView)v.findViewById(R.id.SpeakerName); 
      tv.setText("tt"); 
      /*ImageView iv = (ImageView) v.findViewById(R.id.profilePic); 
      iv.setImageResource(picIds[position]);*/ 

     } 
     else 
     { 
      v = convertView; 
     } 
     return v; 
    } 



} 

あり、ここで、この問題を解決するために私を助けてください、私の活動

public class SavedConferencesActivity extends Activity{ 

    GridView confereneceGridView; 
    ArrayAdapter<String> conferneceAdapter; 
    Button btnUpdate; 

    List<String> conferenceList; 
    TextView txtHeading; 
    Boolean result = false; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 


    } 


    protected void onStart() { 
     super.onStart(); 
     setContentView(R.layout.homegridlayout); 
     initialize(); 

     confereneceGridView.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 

       Toast.makeText(SavedConferencesActivity.this, conferenceList.get(position)+"", Toast.LENGTH_SHORT).show(); 


    } 

    @Override 
    protected void onResume() { 
     // TODO Auto-generated method stub 
     super.onResume(); 

     conferneceAdapter = new SavedConferencesGridAdapter(this, android.R.layout.simple_list_item_1, conferenceList); 
     confereneceGridView.setAdapter(conferneceAdapter); 
    } 


    private void initialize() { 


     confereneceGridView = (GridView) findViewById(R.id.gridOfConference); 
     btnUpdate = (Button) findViewById(R.id.btnUpdate); 
     txtHeading = (TextView) findViewById(R.id.txtTag); 

     conferenceList = new ArrayList<String>(); 
     conferenceList.add("AA"); 
     conferenceList.add("BB"); 
     conferenceList.add("CC"); 

     if (conferenceList.size() == 0) 
      txtHeading.setText("No conferences saved"); 
     else 
      txtHeading.setText("Selected Conferences"); 



    } 




} 

ある

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

    <ImageButton 
     android:id="@+id/profilePic" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/newlocation" 
     android:background="@drawable/btnbackground" 
     /> 

    <TextView 
     android:id="@+id/SpeakerName" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="15sp" 
     android:text="Some Speaker" 
     /> 

私のレイアウト

です。または代替品がある場合は

+0

アダプタとitemclickリスナーを少し投稿できます。アイデアを得ることができるように –

+0

私は私の質問を編集しました。 – NullPointerException

+0

私の問題はまだ解決されていません...しかし、当時私はimageViewを使用し、それにパディングを設定しました... – NullPointerException

答えて

1

シンプルです。グリッド内focussable要素がある場合に

android:focusable="false" 

この問題は、通常発生する、のImageButtonのためにこの属性を提供します。(例:ボタン、のImageButtonなど)。

+0

申し訳ありませんが動作しません..アンドロイド2.1で開発中です – NullPointerException

+0

@Rashmiは 'ImageButton'でfalseにフォーカスを設定していることを確認します –

1

このImageButtonの理由は、デフォルトではクリック可能でフォーカス可能なため、Focusイベントとclickイベントは決してItemViewに移動しません。

プロパティの設定

android:focusable-"false" 

とあなたのアダプタクラスで

android:clickable="false" 
+0

申し訳ありませんが動作しません..私はアンドロイドで開発中です2.1 – NullPointerException

0

、ビュー "V" を返す前に 、追加 "onClickListener" "V"

v.setOnClickListener(new OnClickListener() {   
     @Override 
     public void onClick(View v) { 
       Toast.makeText(context, position, Toast.LENGTH_SHORT).show(); 
     } 
}); 
+0

android:descendantFocusability = "beforeDescendants"これをメインの線形レイアウトに追加して試してください。 –

+0

は試してみましたが、動作していません..他の解決策/方法が分かりました。 – NullPointerException

+0

私の編集した答えをチェックしてください – Pallavi

1

商品のレイアウトは次のとおりです:

<LinearLayout ... 
    android:descendantFocusability="blocksDescendants"> 
<ImageButton ... 
    android:focusable="false" 
    android:focusableInTouchMode="false"/> 
</LinearLayout> 

AdapterのImageButtonのsetOnClickListenerを忘れないでください。