ListView在我的控制器类Android中不起作用

时间:2014-04-21 17:44:16

标签: java android onitemclicklistener

我的应用有问题。我已经用视图和控制器实现了mvc设计模式。控制器具有OnClickListener方法(4个按钮和列表视图)。问题是当活动开始时按钮听众响应但列表视图完全是站点,我无法点击,我无法滚动列表。
我告诉你我的代码。我希望有任何帮助。

all_products.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/myLayout">

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="389dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true">

</ListView>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Mapa" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/button1"
    android:text="Lista" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/button2"
    android:text="Buscador" />

<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/button3"
    android:text="Más" />


主要活动

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.all_products);


   final MyModel myModel = new MyModel();
   final MyView myView = new MyView(this);
   MyController myController = new MyController(this, myModel, myView);

   ViewGroup container = (ViewGroup) findViewById(R.id.myLayout);
   container.addView(myView);
   container.addView(myController); 

   Bundle b=this.getIntent().getExtras();
   String[] array=b.getStringArray("listaEventos");

   //A continuación, generamos los distintos valores que ocuparán el LinearLayout, concretamente
   //las categorías de los eventos.
   String[] values = new String[] { "Actividades vacacionales", "Aire libre y excursiones", "Cine",
    "Conferencias y otros", "Congresos y jornadas", "Cursos y talleres", "Deporte", "Escénicas",
    "Exposiciones", "Ferias", "Fiestas y festivales", "Música", "Viajes", "Otras" };

   //Llamamos al adapter personalizado para mostrar la vista.
   MyListCategoryArrayAdapter adapter = new MyListCategoryArrayAdapter(this, values, array);
   setListAdapter(adapter);

}

控制器

public class MyController extends RelativeLayout{

 public MyController(Activity activity, 
      final MyModel myModel, final MyView myView) {
super(activity, null);
LayoutInflater layoutInflater = 
          (LayoutInflater)activity.getSystemService   
                  (Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.all_products, this);

final Button button0 = (Button) view.findViewById(R.id.button1);
button0.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Log.d("Boton0", "Boton0");

    }
});

final Button button1 = (Button) view.findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Log.d("Boton1", "Boton1");

    }
 }); 

final Button button2 = (Button) view.findViewById(R.id.button3);
button2.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Log.d("Boton2", "Boton2");

    }
}); 

final Button button3 = (Button) view.findViewById(R.id.button4);
button3.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Log.d("Boton3", "Boton3");

    }
}); 

ListView list = (ListView) view.findViewById(android.R.id.list);
list.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, 
            View view, int position, long id) {
        Log.d("Pulsando en lista", "Pulsando en lista");
    }
});

0 个答案:

没有答案