2013-02-13 57 views
1

我有3個菜單選項卡作爲Fragment1,fragment2。其中兩個片段有listView和onClickListener,另外一個片斷只是一個片段。片段Onclicklistener

當片段是在聚焦和用戶觸摸一個空的空間,Fragmentlist的onclick聽者反應:

enter image description here

enter image description here

片段代碼:一個與onclicklistener

片段1:

public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    setListAdapter(new ArrayAdapter<String>(getActivity(), 
      R.layout.fragment_genere_view,GENERE_TITLES)); 
    getListView().setBackgroundColor(Color.BLACK); 
      } 

public void onListItemClick(ListView l, View v, int position, long id) { 
    Intent intent = new Intent(); 
    intent.setComponent(new ComponentName("package", GENERE_CLASSES[position])); 
    startActivity(intent); 
} 

片段2:

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    View myFragmentView = inflater.inflate(R.layout.fragment_search_view, container, false); 

    return myFragmentView; 
    } 
+0

請發佈您的代碼也。沒有那麼難以分辨發生了什麼。 – 2013-02-13 18:19:15

+0

發佈了用於創建這兩個片段的代碼,片段1是一個列表視圖,onClicklistener在應用程序第一次加載時加載,片段2是佈局,當片段2處於焦點並且用戶觸摸空白區域時,片段1 onclicklisterner反應。 – amitsalyan 2013-02-13 18:26:09

+0

希望我可以添加圖片以更好地說明問題。需要10個或更多的聲望才能這樣做 – amitsalyan 2013-02-13 18:55:06

回答

相關問題