I have an inflated layout inside an AlertDialog. When I refer to one of its view I get a NullpointerException.
The view with id spinner lies inside the layout dialog_with_spinner.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp">
<TextView
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="#string/info_title" />
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:entries="#array/entries"
android:saveEnabled="true"/>
</LinearLayout>
<CheckBox
android:id="#+id/someId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/someString"/>
</LinearLayout>
Code:
AlertDialog.Builder builder = new AlertDialog.Builder(boxThemeContextWrapper);
LayoutInflater inflater = getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_with_spinner, null))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
final Spinner sp = (Spinner) findViewById(R.id.spinner);
int p = sp.getSelectedItemPosition(); // this gets the **NullPointerException**
String[] entryValues = getResources().getStringArray(R.array.entry_values);
final String entry = entryValues[p];
useMyEntryMethod(entry);
}
})
.setNegativeButton(R.string.dialogs_negative, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//
}
});
builder.show();
How do I fix this? thanks.
Replace
final Spinner sp = (Spinner) findViewById(R.id.spinner);
with
final Spinner sp = (Spinner) dialog.findViewById(R.id.spinner);
Access Spinner with dialog's reference for findViewById().
Update:
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_with_spinner, null);
setView(view)
And then Access Spinner using view, Like,
final Spinner sp = (Spinner) view.findViewById(R.id.spinner);
Related
I know they are similar questions but I could not make them work. I have a list fragment which includes the item in my array list and a button next to it for each element in my array list. My ultimate goal is to make program respond only when the user clicks to button but I could not even manage to detect the clicks on the screen. I also tried setting button's focusable to false(suggested from other questions) but that also did not work. Here is my code.
public class ResultListFragment extends ListFragment {
private List<String> listValues, keyValues;
private String email, username;
private ArrayAdapter<String> myAdapter;
private ListView myListView;
private TextView title;
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_resultlist, container, false);
return view;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
View v = getView();
myListView = getListView();
listValues = new ArrayList<String>();
myAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),
R.layout.fragment_rowlayout, R.id.myListText, CameraActivity.resultList);
setListAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
#Override
public void onListItemClick(ListView l, View v, final int position, long id) {
super.onListItemClick(l, v, position, id);
Log.d("blabla", "onListItemClick: clicked to : "+position);
final String delete=CameraActivity.resultList.get(position);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setCancelable(true);
builder.setTitle("DELETION");
builder.setMessage(delete + " delete it.");
builder.setPositiveButton("Onayla",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getActivity().getApplicationContext(), delete+ "has been deleted", Toast.LENGTH_SHORT).show();
CameraActivity.resultList.remove(position);
myAdapter.notifyDataSetChanged();
for(String st:CameraActivity.resultList){
Log.d("TAG", "onClick: eleman: " +st);
}
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
Here are my xml files
fragment result list
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:background="#drawable/cembutton"
android:text="Yükle"
android:id="#+id/load"
android:layout_alignRight="#+id/results"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:textStyle="bold"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No data"/>
</RelativeLayout>
and fragment_rowlayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
>
<TextView
android:id="#+id/myListText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:textStyle="bold"
android:textColor="#3700ff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawable="#drawable/cembutton"
android:layout_alignParentRight="true"
android:text="Çıkart"
android:layout_marginRight="50dp"/>
</RelativeLayout>
You should provide custom adapter for your listview.
Then, in getView() method you can find your button by id and set onClickListener to it.
I'd need your help to do something in Android, in the following the use case.
I have created a custom dialog in Android, whose layout is:
dialog_threshold.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp">
<ImageView
android:src="#drawable/ic_media_route_on_03_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:background="#FFFFBB33"
android:contentDescription="#string/set_target" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner_threshold" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layout_threshold">
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/targetSelected"
android:layout_weight="1" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/threshold_operator_spinner"
android:layout_weight="1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="#+id/threshold_val"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
And in the Activity, when I click on a specific button, I have something like this, to create the custom dialog:
setThreshold_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder mBuilder = new AlertDialog.Builder(DiseaseActivity.this);
//Inflate the custom layout
View mView = getLayoutInflater().inflate(R.layout.dialog_threshold, null);
//Set title for dialog
mBuilder.setTitle("Set thresholds for your target");
//Define the spinner inside your custom layout
final Spinner mSpinner = (Spinner) mView.findViewById(R.id.spinner_threshold); //because it doesn't exist in the main layout, but only in the custom layout
//Define the ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(DiseaseActivity.this,
android.R.layout.simple_spinner_item,
getResources().getStringArray(R.array.threshold_choices));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinner.setAdapter(adapter);
if (!mSpinner.getSelectedItem().toString().equalsIgnoreCase("Choose a threshold option")) {
String ThresholdSelection = mSpinner.getSelectedItem().toString();
}
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if ((dialog2 != null) && dialog2.isShowing() && !mSpinner.getSelectedItem().toString().equalsIgnoreCase("Choose a threshold option")) {
dialog2.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
} else {
dialog2.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
//Set the positive and negative button for the custom dialog
mBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
disease.setThreshold(mSpinner.getSelectedItem().toString());
if (!mSpinner.getSelectedItem().toString().equalsIgnoreCase("Choose a threshold option")) {
Toast.makeText(DiseaseActivity.this,
mSpinner.getSelectedItem().toString(),
Toast.LENGTH_SHORT)
.show();
setInterval_button.setEnabled(true);
}
}
});
mBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
mBuilder.setView(mView);
dialog2 = mBuilder.create();
dialog2.show();
dialog2.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
});
What I want to do now is to add dynamically other components (like EditText or TextView) to the above Dialog before is it shown.
How can I do it?
Thanks in advance!
just create your custom view >> find the parent(in which viewgroup you want to add) >>> and add it. eg:-
mView.addView(new TextView(ActivityContext),LayoutParamss);
mBuilder.setView(mView);
I'm using a listview in an alertdialog, but when the dialog shows, its doesn't display anything. The object is not empty as I'm filling it and adding it to the array list before the alertdialog. Heres the code for my xml and classes:
Where I'm setting the adapter:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Select a match");
//insert array to constructor
LayoutInflater inflater = getLayoutInflater(savedInstanceState);
View dialogLayout = inflater.inflate(R.layout.dialoglist, null);
matchAdapter testAdapter = new matchAdapter(getContext(), userInfos);
ListView listView = (ListView) dialogLayout.findViewById(R.id.dialogListView);
listView.setAdapter(testAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//do something
}
});
builder.setView(dialogLayout);
AlertDialog alert = builder.create();
alert.show();
custom adapter:
class matchAdapter extends ArrayAdapter<userInfo> {
public matchAdapter(Context context, ArrayList<userInfo> test) {
super(context, R.layout.match_result, test);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View customRow = inflater.inflate(R.layout.match_result, parent, false);
userInfo singleItemTest = getItem(position);
/*
TODO: get references to layout elements
*/
TextView username = (TextView) customRow.findViewById(R.id.matchUsername);
TextView sex = (TextView) customRow.findViewById(R.id.matchSex);
TextView age = (TextView) customRow.findViewById(R.id.matchAge);
Button sendRequest = (Button) customRow.findViewById(R.id.matchSendRequest);
username.setText(singleItemTest.getUserName());
return customRow;
}}
row.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/match_result"
android:orientation="horizontal"
android:padding="16dp"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="left">
<TextView
android:id="#+id/matchUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/matchSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sex"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/matchAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:layout_marginRight="10dp"/>
<Button
android:id="#+id/matchSendRequest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Request"
android:minHeight="5dp"
android:minWidth="0dp"
android:layout_marginLeft="80dp"/>
dialoglist.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialogListView"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</ListView>
In your Adapter add a object ArrayList<userInfo> infos
Now in Constractor use this
public matchAdapter(Context context, ArrayList<userInfo> test) {
super(context, R.layout.match_result, test);
infos=test;
}
Now getView callback will like this:
userInfo singleItemTest = infos.get(position);
I think this will solve your problem :)
Mike. M was correct in his comment. The arraylist was indeed empty. However I've fixed it now. Dumb oversight on my for loop.
How can i make my alert dialogue into a custom alert in android.please help me to display my dialogue box in a custom alert. my code is pasted here.
the code contains an out put of 10 list view. and when click on item in the list it could be alerted..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the ListView resource.
mainListView = (ListView) findViewById( R.id.mainListView );
// Create and populate a List of planet names.
final String[] planets = new String[] { "Allu", "Abin", "Bibin", "Aswathy",
"Jibin", "Saran", "Jobin", "Neethu","ammu","Ram"};
final ArrayList<String> planetList = new ArrayList<String>();
planetList.addAll( Arrays.asList(planets) );
// Create ArrayAdapter using the planet list.
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, planetList);
/*// Add more planets. If you passed a String[] instead of a List<String>
// into the ArrayAdapter constructor, you must not add more items.
// Otherwise an exception will occur.
listAdapter.add( "Ceres" );
listAdapter.add( "Pluto" );
listAdapter.add( "Haumea" );
listAdapter.add( "Makemake" );
listAdapter.add( "Eris" );*/
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter( listAdapter );
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Alert Dialog With EditText"); //Set Alert dialog title here
alert.setMessage("Edit Your Name Here"); //Message here
final EditText input = new EditText(context);
input.setText((String)planetList.get(position));
alert.setView(input);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String srt = input.getEditableText().toString();
Toast.makeText(context,srt, Toast.LENGTH_LONG).show();
planetList.set(position, srt);
listAdapter.notifyDataSetChanged();
}
});
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
}); //End of alert.setNegativeButton
AlertDialog alertDialog = alert.create();
alertDialog.show();
}
});
}
}
That's a simple way to make a popup dialog with a custom xml layout, It will surely work:
Make an xml file for your dialog. Set android:layout_width="wrap_content" and android:layout_height="wrap_content" or any other size. You can also set a background for your layout.
For example this is an xml layout for a popup window:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/black" >
<TextView
android:id="#+id/title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="title"
android:textColor="#color/white"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:id="#+id/details_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="40dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Enter your name here:"
android:textColor="#color/white"
android:layout_weight="1"
android:layout_gravity="center"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_gravity="center"
android:layout_marginRight="8dp"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="#+id/editText"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
style="?android:attr/buttonBarStyle" >
<Button
android:id="#+id/cancel_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"
android:onClick="cancel"
android:textColor="#color/white"
style="?android:attr/buttonStyle" />
<Button
android:id="#+id/exit_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="OK"
android:onClick="ok"
android:textColor="#color/white"
style="?android:attr/buttonStyle" />
</LinearLayout>
</LinearLayout>
And that's how you show the popup:
private void showPopup(final Activity context) {
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup_layout);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layoutPopup = layoutInflater.inflate(R.layout.layout_popup, viewGroup);
popup = new PopupWindow(context);
popup.setContentView(layoutPopup);
popup.setWidth(LayoutParams.WRAP_CONTENT);
popup.setHeight(LayoutParams.WRAP_CONTENT);
popup.setFocusable(true);
popup.showAtLocation(layoutPopup, Gravity.CENTER, 0, 0);
}
You can use simple onClick methods for buttons in your popup dialog:
public void cancel(View v){
Toast.makeText(getApplicationContext(), "Canceled",
Toast.LENGTH_LONG).show();
popup.dismiss();
}
public void ok(View v){
Toast.makeText(getApplicationContext(), "Done",
Toast.LENGTH_LONG).show();
popup.dismiss();
}
You can also read this for another way of creating custom dialogs.
public class MyDialog extends DialogFragment {
public static MyDialog getInstance() {
MyDialog dialog = new MyDialog ();
Bundle bundle = new Bundle();
bundle.putInt("your key", "save something");
dialog.setArguments(bundle);
return dialog;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder vBuilder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = inflater.inflate(R.layout."your custom layout", null);
yourEditText = (TextView) view.findViewById(R.id."your edit text id");
Bundle bundle = getArguments();
if(bundle!=null){
... do something
}
vBuilder.setView(view);
return vBuilder.create();
}
}
To open this dialog
MyDialog.getInstance().show(getFragmentManager(), "your TAG");
Why can't you use dialog?
dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);//create an xml and use it.
dialog.setCancelable(true);
passwordEmail = (EditText) dialog
.findViewById(R.id.dialog_txt_name);
dialog.show();
Instead of this :
final EditText input = new EditText(context);
input.setText((String)planetList.get(position));
alert.setView(input);
Write this :
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = inflater.inflate(R.layout."your custom layout", null);
alert.setView(view);
I have an Alert Dialog Box that pops up on the click of a ListView item. The Alert Dialog has a custom layout containing two EditTexts and a TextView. However on calling EditText.getText() on the click of the OK button on the dialog, the application crashes with java.lang.NullPointerException. Please help me in debugging it.
The listview onClickListener code :
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
String cn = cursor.getString(cursor.getColumnIndex("CourseName"));
//Toast.makeText(getApplicationContext(), "Selected: "+cn, Toast.LENGTH_SHORT).show();
LayoutInflater lf = LayoutInflater.from(List_of_Courses.this);
final View DialogView = lf.inflate(R.layout.dialog, null);
final EditText input1 = (EditText) findViewById(R.id.attendanceet);
final EditText input2 = (EditText) findViewById(R.id.totalclasseset);
final AlertDialog.Builder alert = new AlertDialog.Builder(List_of_Courses.this);
alert.setTitle(cn).setView(DialogView).setPositiveButton("OK",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int whichbutton) {
Log.v("Test","We're checking");
input1.getText();
input2.getText();
Log.v("Test","We're good");
Log.v("Dialog", input1.getText().toString());
Log.v("Dialog", input2.getText().toString());
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int whichbutton) {
//User clicked cancel so doing nothing.
Log.v("CancelDialog", "User clicked Calcel");
}
});
alert.show();
}
});
The dialog.xml code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:id="#+id/DialogLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingLeft="25sp"
android:paddingRight="25sp" >
<EditText
android:id="#+id/attendanceet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_weight="1"
android:inputType="number" >
</EditText>
<LinearLayout
android:orientation="vertical"
android:id="#+id/tvLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6sp" >
<TextView
android:id="#+id/outof"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:textSize="20sp"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:textColor="#FFFFFF" >
</TextView>
</LinearLayout>
<EditText
android:id="#+id/totalclasseset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_weight="1"
android:inputType="number" >
</EditText>
</LinearLayout>
</RelativeLayout>
You should use the dialog object to intialize input1 an input 2.
final View DialogView = lf.inflate(R.layout.dialog, null);
final EditText input1 = (EditText) DialogView.findViewById(R.id.attendanceet);
You can findViewById of the current view hierarchy set to the activity. In your case you inflate a dialog and you current view is the dialog on listview item click. So you should use the dialog object to initialize the views.
You can remove the final modiifier for the below
AlertDialog.Builder alert = new AlertDialog.Builder(List_of_Courses.this);
final EditText input1 = (EditText) findViewById(R.id.attendanceet);
final EditText input2 = (EditText) findViewById(R.id.totalclasseset);
should be
final EditText input1 = (EditText) DialogView.findViewById(R.id.attendanceet);
final EditText input2 = (EditText) DialogView.findViewById(R.id.totalclasseset);
You have to create an AlertDialog before calling show() method. And call show() method on created AlertDialog not on AlertDialogBuilder.
// create alert dialog
AlertDialog alertDialog = alert.create();
Look at this example for reference.