3

I 'm new to android and what want to make a custom Adapter so that each row would hold an image and next to it some information.I want also to place a textField.I did so but i can't use them,meaning they appear as they should be but when i touch it it never open the softkeyboard.My guess is that it doesn't get the requested focus.Any ideas?I'll post the xml i've written so much must be a field that i'm missing.Thank you so much for your time.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip"
    android:descendantFocusability="blocksDescendants" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_marginRight="6dip"
    android:src="@drawable/std" />

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


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/padding_small"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name" />



    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="45dp"
        android:text="TextView"
        android:textSize="10dp" />

</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/padding_small"
    android:orientation="horizontal" >



    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Grade" />





<EditText
    android:id="@+id/txtPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword" >

</EditText>

</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/padding_small"
    android:orientation="horizontal" >



    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Comment" />










    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="25dp"
        android:textSize="10dp" />

</LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/padding_small"
            android:orientation="horizontal" >



    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Present" />


    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp" />

</LinearLayout>

and that's my getView method

    public View getView(final int position, View convertView, ViewGroup parent) {


    convertView=null;


    ViewHolder holder;

    if (convertView == null) {

        convertView = mInflater.inflate(com.example.myapp.R.layout.rw, null);           

        TextView tt = (TextView) convertView.findViewById(mIds[1]);
        TextView bt = (TextView) convertView.findViewById(mIds[0]);
        TextView btt = (TextView) convertView.findViewById(mIds[2]);
        EditText bttt = (EditText) convertView.findViewById(mIds[3]);
        TextView a = (TextView) convertView.findViewById(mIds[4]);
        TextView av= (TextView) convertView.findViewById(mIds[5]);
        TextView avt= (TextView) convertView.findViewById(mIds[6]);
        CheckBox check = (CheckBox) convertView.findViewById(mIds[7]);


        if (tt != null) {
              tt.setText(mContent.get(position));
              tt.setTextColor(Color.RED);
       }
        if(bt != null){
              bt.setText("Name: ");
              bt.setTextColor(Color.BLUE);
        }
        if(btt != null){
              btt.setText("Grade:");
              btt.setTextColor(Color.BLUE);
        }
        if(a != null){
          a.setText("Comments:"); 
          a.setTextColor(Color.BLUE);
      }
      if(av != null){
          av.setText("..."); 
          av.setTextColor(Color.RED);
      }
      if(avt != null){
          avt.setText("Present:"); 
          avt.setTextColor(Color.BLUE);
      }

      holder = new ViewHolder(tt);

          ((CheckBox)convertView.findViewById(mIds[7])).setOnCheckedChangeListener(new
              onCheckedChangeListener() { 

            public void onCheckedChanged(CompoundButton buttonView, 
                                                    boolean isChecked) { 
              // TODO Auto-generated method stub 
              if (buttonView.isChecked()) { 
                  checkModel.get(position).status=true;
              } 

            }
           });


    }else {

    holder = (ViewHolder) convertView.getTag();

     }   



       ((CheckBox)convertView.findViewById(mIds[7])).setChecked(checkModel.get(position).status);
     ((EditText) convertView.findViewById(mIds[3])).setText("lalla");

         return convertView;
     }
user1746708
  • 691
  • 1
  • 8
  • 16

2 Answers2

1

to hold a image next to textview do the following in your code in onCreate() :

          phoneno.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(android.R.drawable.sym_action_call), null);
G M Ramesh
  • 3,420
  • 9
  • 37
  • 53
1

I think, android is taking the click as the click on the ListView rather than your TextView. Try tweaking these settings for your components other than EditText

android:focusable="false"
android:focusableInTouchMode="false"

or try

android:focusable="true"
android:focusableInTouchMode="true"

for your EditText.

And why do you have so many LinearLayouts, try replacing it with a RelativeLayout

ThePCWizard
  • 3,338
  • 2
  • 21
  • 32
  • Well that seemed to work but when i touch the editText i can i write as expected but when i press done on the softkeyboard it erases it. – user1746708 Oct 22 '12 at 14:29
  • and what happens when you press the back button while the softkeyboard is visible? I would strongly recommend you to clean up your xml as it seems really heavy for a list_item. – ThePCWizard Oct 22 '12 at 14:37
  • I know it is right? but it's what i was asked for.I have to do this instead of dataGrid view.So i have not any alternative.When i press back i go back one activity – user1746708 Oct 22 '12 at 14:40
  • My problem is that when i press done what I've written so far clear from the editText – user1746708 Oct 22 '12 at 15:04
  • 'Done' button on SoftKeyboard? or do you have a custom button? – ThePCWizard Oct 22 '12 at 15:55
  • No on the keyboard.I still think it is because of the focusability.I think that it is lost in the listView.But this is just a guess – user1746708 Oct 22 '12 at 16:47
  • How about capturing the 'done' button and setting the text manually... this can help: http://stackoverflow.com/questions/3031887/how-to-catch-a-done-key-press-from-the-soft-keyboard – ThePCWizard Oct 22 '12 at 17:04
  • well this seems to work.But i think that if i do this then in order for the text to appear i must call notifyDatasetChanged on the adapter so this will probably make it slower – user1746708 Oct 22 '12 at 17:39
  • add your getView method, maybe someone else could help! – ThePCWizard Oct 22 '12 at 17:43