0

这是我点击自定义列表视图的代码。当我单击标题时,它可以工作,但在标题之后它不起作用。CustomAdapter是我的应用程序中的另一个类,我在其中定义了列表视图的标题和所有变量。请帮我解决这个问题。

      import android.app.Activity;
      import android.content.Intent;
      import android.os.Bundle;
      import android.text.Html;
      import android.view.View;
      import android.widget.AdapterView;
      import android.widget.Toast;
      import android.widget.AdapterView.OnItemClickListener;
      import android.widget.ListView;

         public class ProbabilityConditional extends Activity {
String htmlcodefor_root = "&#x221A", htmlcodefor_multiply = "&#xD7",
htmlcodefor_divide = "&#xF7", htmlcodefor_underroot = "&#00B3";
ListView listView1;
String htmlcodefor_space = "&#8194", htmlcodefor_pi = "&#928",
htmlcodefor_largespace = "&#8195";
String htmlcodefor_implies = "&#x21D2";
String htmlcodefor_i = "&#7522";
String htmlcodefor_angle = "&#952";
String htmlcodefor_overline = "&#x203E", htmlcodefor_plusminus = "&#177";



// TextView txtv;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // txtv = (TextView)findViewById(R.id.txtTitle);
    // txtv.setText(Html.fromHtml("1.(constant)<sup><small>0</></> = 1"));
    listView1 = (ListView) findViewById(R.id.listView1);

    CustomAdapter.formula_one_custom_adapter_class_var =  Html.fromHtml("1  ");
    CustomAdapter.formula_two_custom_adapter_class_var = Html.fromHtml("2  ");

    CustomItemCall formula_data[] = new CustomItemCall[] {
                new                                                           CustomItemCall(CustomAdapter.formula_one_custom_adapter_class_var),
            new CustomItemCall(CustomAdapter.formula_two_custom_adapter_class_var),

    };
    CustomAdapter adapter = new CustomAdapter(this,R.layout.listview_item_row, formula_data);

    View header = (View) getLayoutInflater().inflate(R.layout.listview_header_row, null);
    listView1.addHeaderView(header);

    listView1.setAdapter(adapter);
    listView1.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
            System.out.println(position);
            Toast.makeText(ProbabilityConditional.this,position + "  " , Toast.LENGTH_LONG).show();
            // When clicked, show a toast with the TextView text
            if (position == 1) {
                startActivity(new Intent(ProbabilityConditional.this,ProbabilityConditionalDiscrete.class));
            } if (position == 2) {
                startActivity(new Intent(ProbabilityConditional.this,ProbabilityConditionalContinuous.class));
            }

        }
    });
}

}
4

2 回答 2

0

使您的 listview 可聚焦 true 在您的 xml 中添加这些行android:focusable="true" 并使列表的其他项目变为 falseandroid:focusable="false "

listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                    System.out.println(position);
                    Toast.makeText(ProbabilityConditional.this,position + "  " , Toast.LENGTH_LONG).show();
                    // When clicked, show a toast with the TextView text
                    if (position == 1) {
                        startActivity(new Intent(ProbabilityConditional.this,ProbabilityConditionalDiscrete.class));
                    } if (position == 2) {
                        startActivity(new Intent(ProbabilityConditional.this,ProbabilityConditionalContinuous.class));
                    }

                }
            });
于 2012-10-11T05:25:15.287 回答
0

像这样写代码,简单的方法:- ListView 列表;list.setOnItemClickListener(new OnItemClickListener() {

       public void onItemClick(AdapterView parent, View view,
               int position, long id) 
       {
               //if in future you need to start a new activity
               //then add below line also in your activity

         Intent in = new Intent(MainActivity.this, SecondActivity.class);
                         startActivity(in);
                          }                                  
           });   
于 2012-10-13T10:54:16.300 回答