Question

when click on text nothing happened. there is not exception in CatLog or showing any error. i checked Manifest file and c_programs_start_51_100.xml file but i found nothing wrong still struggling find out the problem. The function Onclick() doesn't executed at single when i check in CatLog. please help me resolve the problem.

Thanks in advance.

public class C_Programs_Start_51_100 extends Activity implements View.OnClickListener{

TextView textViewC51;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c_programs_start_51_100);

    textViewC51 = (TextView) findViewById(R.id.textView51);
    textViewC51.setOnClickListener(this);       
}


@Override
public void onClick(View view) {

    Log.d("press", "second" + view.getId());

    switch(view.getId()) {

    Log.d("press", "first");

    case R.id.textView51:

        Log.d("press", "first");

        Intent intent51 = new Intent(C_Programs_Start_51_100.this, C_Programs_P51.class);
        startActivity(intent51);

        Log.d("press", "second");

        break;



    }

}

}

// Here is my xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/relativeLayout1"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".First" >

     <ScrollView 
         android:id="@+id/scrollView1"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/table_vertical_margin"
            android:paddingLeft="@dimen/table_horizontal_margin"
            android:paddingRight="@dimen/table_horizontal_margin"
            android:paddingTop="@dimen/table_vertical_margin"
        >

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" > 



        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/table_vertical_margin"
            android:paddingLeft="@dimen/table_horizontal_margin"
            android:paddingRight="@dimen/table_horizontal_margin"
            android:paddingTop="@dimen/table_vertical_margin"

            >

            <TextView
            android:id="@+id/textView51"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:linksClickable="true"
            android:focusableInTouchMode="true"
            android:text="@string/txtPn51" />
            <TextView
            android:id="@+id/textViewC51"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:linksClickable="true"
            android:focusableInTouchMode="true"
            android:textSize="15sp"
            android:focusable="true"
            android:fitsSystemWindows="true"
            android:text="@string/txtC51" />
        </TableRow>


    </LinearLayout>
  </TableLayout>
  </ScrollView>
</RelativeLayout>
Was it helpful?

Solution

You seem to have two textViews one with

id = textView51

id = textViewC51

in your onCreate you are trying to find the first textview and pass it to another

textViewC51 = (TextView) findViewById(R.id.textView51);

Try to change the previous line with:

    textViewC51 = (TextView) findViewById(R.id.textViewC51);

and see if it works for you.

OTHER TIPS

Seems like you are trying to implement something when the user clicks the textview.If this is the case you can just use a spinner, Where you can implement the said functionality without much complexity

you implemented the View.OnClickListener and I'm assuming that you also include in the xml the android:onclick attribute in your xml file?..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top