Saturday, 3 December 2016

Android converting from LinearLayout to CheckedTextView and TextView

Question;
I have customized my own listview, which consists of:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="5dp">

<CheckedTextView
    android:id="@+id/txt_lan"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:textSize="25sp" /></LinearLayout>
and i want to be able to show what text is inside my CheckedTextView:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getApplicationContext(), (((TextView)CheckedTextView)view).getText().ToString(), Toast.LENGTH_SHORT).show();
So as I assume, view contains reference to my LinearLayout. How to access the text in CheckedTextView? Becouse my way doesn't seem to work

1st Answers

;




@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

     CheckedTextView checkedTextView = (CheckedTextView)arg1.findViewById(R.id.checkedTextView1);
        // do anything to checkedTextView now 
        checkedTextView.toggle();

                    }
see how the param arg1 is used and this should work!





No comments:

Post a Comment