In my application customize Alear Box is there. In this alert box there is a customize ListView in which one TextView and one EditText is there. Every thing work fine and Alert Box coming on the screen perfectly.
But when I tap on Edit text to fill the characters into the Edit Text, Android Softkey on appearing. Therefore I am not able to insert and data into Edit Text.
My Code:-
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
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=".MainActivity" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Population"
android:onClick="getPopulation" />
</RelativeLayout>
alert_box.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:listitem="@layout/list_view_resourse" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Add" />
<Button
android:id="@+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
list_view_resourse.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/district"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textColor="#000000"
android:textStyle="bold" />
<EditText
android:id="@+id/population"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
MainActivity
package com.exmp;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends Activity implements OnClickListener{
private ArrayAdapter<Disrict> adapter;
private ArrayList<Disrict> disricts;
private ListView lView;
private Button add, cancel;
private AlertDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void getPopulation() {
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.alert_box, null);
lView = (ListView) view.findViewById(R.id.lView);
add = (Button) view.findViewById(R.id.add);
cancel = (Button) view.findViewById(R.id.cancel);
disricts = new ArrayList<Disrict>();
disricts.add(new Disrict(1, "Bangalore", 45.22));
disricts.add(new Disrict(1, "Gulbarga", 22.22));
adapter = new DistrictAdapter(MainActivity.this, R.layout.list_view_resourse, disricts);
lView.setAdapter(adapter);
cancel.setOnClickListener(this);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Population");
alert.setView(view);
alert.setCancelable(false);
dialog = alert.create();
dialog.show();
}
public void getPopulation(View v){
getPopulation();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.add:
break;
case R.id.cancel:
dialog.dismiss();
break;
}
}
}
Disrict
package com.exmp;
public class Disrict {
private int id;
private String strDistrict;
private double population;
public Disrict(int id, String strDistrict, double population) {
super();
this.id = id;
this.strDistrict = strDistrict;
this.population = population;
}
public int getId() {
return id;
}
public String getStrDistrict() {
return strDistrict;
}
public double getPopulation() {
return population;
}
@Override
public String toString() {
return strDistrict;
}
}
DistrictAdapter
package com.exmp;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
public class DistrictAdapter extends ArrayAdapter<Disrict> {
private final Context context;
private final int rowResourceId;
private final ArrayList<Disrict> disricts;
public DistrictAdapter(Context context, int resource,
ArrayList<Disrict> disricts) {
super(context, resource, disricts);
this.context = context;
this.rowResourceId = resource;
this.disricts = disricts;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Spinner spinnerPaymentType = null;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(rowResourceId, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.district);
textView.setText(disricts.get(position).getStrDistrict());
return rowView;
}
}