I have Listview with editext and textview.
When i touch on edittext then edittext lost focus!
I resolved this problem by setting android:windowSoftInputMode="adjustPan"(AndroidManifest.xml)
.
Now i touch on edittext than editext get focus but application label and some raw of listview disappear(top part).
I want to get focus when user touch on edittext without loss application label and some raw of listview.
Code that i have implemented :
Below coding get focus when user touch on edittext but application label and some raw of listview disappear when soft keypad pop up.I want to get focus when user touch on edittext without loss application label and some raw of listview.
1)AndroidManifest.xml
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyListViewDemoActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
2) raw_layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/mEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
3) main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/mListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
4) MyListViewDemoActivity
public class MyListViewDemoActivity extends Activity {
private ListView mListView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mListView=(ListView)findViewById(R.id.mListView);
mListView.setAdapter(new MyAdapter(this));
}
}
class MyAdapter extends BaseAdapter {
private Activity mContext;
private String character[]={"a","b","c","d","e","f","g","h","i","j"};
public MyAdapter(Activity context)
{
mContext=context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return character.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
private class Holder
{
EditText mEditText;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final Holder holder;
if (convertView == null) {
holder = new Holder();
LayoutInflater inflater =mContext.getLayoutInflater();
convertView = inflater.inflate(R.layout.raw_layout, null);
holder.mEditText = (EditText) convertView
.findViewById(R.id.mEditText);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.mEditText.setText(character[position]);
holder.mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (!hasFocus){
final EditText etxt = (EditText) v;
holder.mEditText.setText(etxt.getText().toString());
}
}
});
return convertView;
}
}