final AlertDialog builder = new AlertDialog.Builder(activity).create();
LayoutInflater factory = LayoutInflater.from(activity);
View view = factory.inflate(R.layout.inventory_item_pop_up, null);
builder.setView(view);
ImageButton discardButton = (ImageButton) view.findViewById(R.id.popup_discard);
discardButton.setClickable(true);
discardButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
listener.remove(f);
builder.dismiss();
}
});
This button click does not respond at all. How can I make this piece of code work?
I use this code in an Adapter, by the way.
the onCLickListener you have registered, is it DialogInterface.OnClickListener? If you have used onCLickListener from View class then that won't work here. Please recheck.
You need to do
discardButton.setOnClickListener(new DialogInterface.OnClickListener() {
#Override
public void onClick(View v) {
listener.remove(f);
builder.dismiss();
}
});
I hope this will helpfull for you. I implement this way for custom Dialog
public void showUpdateDialog() {
updateDialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen) {
#Override
public void onBackPressed() {
this.dismiss();
loadDataAsync.execute();
}
};
updateDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
updateDialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
updateDialog.setContentView(R.layout.updatepopup);
logger.info("Network error popup on");
updateDialog.setCancelable(true);
ImageView dialogImage = (ImageView) updateDialog
.findViewById(R.id.dialogheaderimageupdateupdate);
dialogImage.setBackgroundResource(R.drawable.infoimage);
TextView dialogMesage = (TextView) updateDialog
.findViewById(R.id.dialogmessgetextupdate);
TextView currVersion = (TextView) updateDialog
.findViewById(R.id.currentversionupdate);
TextView newVersion = (TextView) updateDialog
.findViewById(R.id.newversionupdate);
TextView dialogHeader = (TextView) updateDialog
.findViewById(R.id.dialogheadertextupdate);
newVersion.setText("Latest version: " + versionCode);
currVersion.setText("Current version : " + currentVersionName);
dialogMesage.setText("Would you like to update now?");
dialogHeader.setText("A program update is available! ");
Button dialogOk = (Button) updateDialog
.findViewById(R.id.dialogokbuttonupdate);
dialogOk.setText("Update");
dialogOk.setFocusable(true);
dialogOk.requestFocus();
dialogOk.setFocusableInTouchMode(true);
dialogOk.requestFocus();
Button dialogCancel = (Button) updateDialog
.findViewById(R.id.dialogcancelbuttonupdate);
dialogOk.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
updateDialog.dismiss();
downLoad = new DownLoad();
downLoad.execute(apkUrl.trim());
}
});
dialogCancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
updateDialog.dismiss();
loadDataAsync.execute();
}
});
try {
updateDialog.show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
And my updatepopup.xml is displayed below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/layoutsample"
style="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/dialoghdrbg"
android:orientation="horizontal" >
<ImageView
android:id="#+id/dialogheaderimageupdateupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/dialogheadertextupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|right"
android:layout_marginLeft="1dp"
android:gravity="center_vertical|right"
android:textColor="#000000"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/dialogcontentbg"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/currentversionupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#ffffff"
android:textSize="23dp"
android:layout_marginTop="10dp"/>
<TextView
android:id="#+id/newversionupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#ffffff"
android:textSize="23dp" />
<TextView
android:id="#+id/dialogmessgetextupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#ffffff"
android:textSize="23dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="15dp"
android:gravity="center|center_horizontal"
android:orientation="horizontal" android:layout_marginBottom="10dp">
<Button
android:id="#+id/dialogokbuttonupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:background="#drawable/buttonanimation"
android:text="#string/OKButton"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="#+id/dialogcancelbuttonupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/buttonanimation"
android:text="#string/CancelButton"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Well, this is awkward... The code is correct, I just wasn't calling the right createDialog() method.
Related
i have a problem when trying to add a programmatically defined radio button to a radio group.
so i have a method that when is called inflates a dialog, this dialog contains within it a list of subjects displayed as a list of checkBox.
since i can't predefine how many subjects are needed in my radio group i decided to add them programmatically using the method mentioned earlier.
for some reason the app keep on crashing every time i open the dialog. with the break point being when the radio button gets added to the radio group.
here is a copy of the fragment responsible of calling the method (as well as the method called) :
public class addPaymentFragment extends Fragment {
private RadioGroup radioGroup;
private RadioButton radioButton;
private SchoolViewModel schoolViewModel;
private NumberPicker numberPicker;
private Button btn;
private Subject subject;
private Dialog dialog;
private RadioGroup radioGroup0;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_add_payment, container, false);
btn = v.findViewById(R.id.btn_add_payment);
radioGroup0 = v.findViewById(R.id.rg_select_subject);
radioGroup = v.findViewById(R.id.rg_add_payment);
numberPicker = v.findViewById(R.id.numberPicker);
numberPicker.setMinValue(0);
numberPicker.setMaxValue(10);
schoolViewModel = new ViewModelProvider(this).get(SchoolViewModel.class);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
schoolViewModel.getSingleTeacherWithSubjects(i).observe(getViewLifecycleOwner(), new Observer<TeacherWithSubjects>() {
#Override
public void onChanged(TeacherWithSubjects teacherWithSubjects) {
if (teacherWithSubjects.subjects.size() > 1) {
openDialog(teacherWithSubjects.subjects,radioGroup0);
} else {
subject = teacherWithSubjects.subjects.get(0);
}
}
});
}
});
schoolViewModel.getAllTeachers().observe(getViewLifecycleOwner(), new Observer<List<Teacher>>() {
#Override
public void onChanged(List<Teacher> teachers) {
addRadioButtons(teachers, radioGroup);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getContext(), teachers.get(0).getTeacherName() + "", Toast.LENGTH_SHORT).show();
}
});
}
});
return v;
}
private void addRadioButtons(List<Teacher> teachers, RadioGroup radioGroup) {
for (Teacher i : teachers) {
//instantiate...
RadioButton radioButton = new RadioButton(getContext());
//set the values that you would otherwise hardcode in the xml...
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
params.bottomMargin = 25;
params.leftMargin = 20;
params.rightMargin = 20;
params.topMargin = 20;
radioButton.setLayoutParams(params);
//label the button...
radioButton.setBackground(new ColorDrawable(Color.TRANSPARENT));
radioButton.setMinWidth(250);
radioButton.setBackgroundResource(R.drawable.custom_checkbox);
radioButton.setElevation(16);
radioButton.setGravity(Gravity.CENTER);
radioButton.setText(i.getTeacherName());
radioButton.setPadding(50, 100, 50, 100);
radioButton.setButtonDrawable(R.drawable.custom_checkbox);
radioButton.setId(i.getTeacherId());
//add it to the group.
radioGroup.addView(radioButton);
}
}
void openDialog(List<Subject> subjects,RadioGroup radioGroup) {
dialog = new Dialog(getContext());
radioGroup = dialog.findViewById(R.id.rg_select_subject);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.choose_teached_subject_dialog);
dialog.setCancelable(false);
Button confirmSubject = dialog.findViewById(R.id.btn_choose_subject);
Button cancelSubject = dialog.findViewById(R.id.btn_dont_choose_subject);
//populate the checkBox
for (int i = 0; i<subjects.size(); i++){
RadioButton radioButton1 = new RadioButton(dialog.getContext());
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
params.bottomMargin = 25;
params.leftMargin = 20;
params.rightMargin = 20;
params.topMargin = 20;
radioButton1.setLayoutParams(params);
radioButton1.setBackground(new ColorDrawable(Color.TRANSPARENT));
radioButton1.setMinWidth(250);
radioButton1.setBackgroundResource(R.drawable.custom_checkbox);
radioButton1.setElevation(16);
radioButton1.setGravity(Gravity.CENTER);
radioButton1.setId(i);
radioButton1.setText(subjects.get(i).getSubjectName());
radioButton1.setPadding(50, 100, 50, 100);
radioButton1.setButtonDrawable(R.drawable.custom_checkbox);
//add it to the group.
radioGroup.addView(radioButton1);
}
confirmSubject.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
Toast.makeText(getContext(), "Select a subject!", Toast.LENGTH_SHORT).show();
}
});
cancelSubject.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
dialog.getWindow().setGravity(Gravity.CENTER);
dialog.show();
}
}
and here is the code to the corresponding XML file :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".addPaymentFragment">
<HorizontalScrollView
android:id="#+id/rv_add_payment"
android:layout_width="match_parent"
android:layout_height="146dp"
android:orientation="horizontal"
android:scrollbars="none"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RadioGroup
android:id="#+id/rg_add_payment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></RadioGroup>
</HorizontalScrollView>
<NumberPicker
android:id="#+id/numberPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="#style/numberPickerTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heures Enseignées :"
android:textColor="#000"
android:textSize="28sp"
app:fontFamily="#font/k2d_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rv_add_payment" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="10dp"
android:src="#drawable/ic_baseline_play_arrow_24"
app:layout_constraintBottom_toBottomOf="#+id/numberPicker"
app:layout_constraintEnd_toStartOf="#+id/numberPicker"
app:layout_constraintTop_toTopOf="#+id/numberPicker" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/numberPicker">
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total: "
android:textColor="#000"
android:textSize="28sp"
app:fontFamily="#font/k2d_semibold" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0DA"
android:textColor="#000"
android:textSize="28sp"
app:fontFamily="#font/k2d_semibold" />
</LinearLayout>
<android.widget.Button
android:id="#+id/btn_add_payment"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="20dp"
android:background="#drawable/rounded_button"
android:text="add"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
<android.widget.Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginEnd="20dp"
android:background="#drawable/rounded_button"
android:text="cancel"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
and here is a copy of the XML file of the dialog called :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#drawable/dialog_background"
android:elevation="16dp">
<TextView
android:id="#+id/choose_subject_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:fontFamily="#font/k2d_semibold"
android:text="choose teached subject :"
android:textColor="#color/black"
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="146dp"
android:orientation="horizontal"
android:scrollbars="none"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/choose_subject_tv">
<RadioGroup
android:id="#+id/rg_select_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"></RadioGroup>
</HorizontalScrollView>
<android.widget.Button
android:id="#+id/btn_choose_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
android:background="#drawable/custom_button"
android:fontFamily="#font/k2d_semibold"
android:text="Confirm"
android:textAllCaps="false"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/horizontalScrollView" />
<android.widget.Button
android:id="#+id/btn_dont_choose_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginBottom="40dp"
android:layout_marginTop="20dp"
android:background="#drawable/custom_button"
android:fontFamily="#font/k2d_semibold"
android:text="Cancel"
android:textAllCaps="false"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/horizontalScrollView" />
</androidx.constraintlayout.widget.ConstraintLayout>
and here is the message shown in the logcat :
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioGroup.addView(android.view.View)' on a null object reference
at com.example.ecolemathphysique.addPaymentFragment.openDialog(addPaymentFragment.java:142)
at com.example.ecolemathphysique.addPaymentFragment$1$1.onChanged(addPaymentFragment.java:62)
at com.example.ecolemathphysique.addPaymentFragment$1$1.onChanged(addPaymentFragment.java:58)
i apologize in advance if there is any mistakes in my question, am a bit new to asking questions here so please take it easy on me and thanks in advance
so i have managed to find the problem which was i called
radioGroup = dialog.findViewById(R.id.rg_select_subject);
before finishing setting up the dialog, which mean that the radioGroup object was never assigned.
here is how the related bloc looks like after fixing it :
void openDialog(List<Subject> subjects,RadioGroup radioGroup) {
dialog = new Dialog(getContext());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.choose_teached_subject_dialog);
dialog.setCancelable(false);
radioGroup = dialog.findViewById(R.id.rg_select_subject);
Button confirmSubject = dialog.findViewById(R.id.btn_choose_subject);
Button cancelSubject = dialog.findViewById(R.id.btn_dont_choose_subject);
Hello Guys ,
I had edited my question with the screenshot, as you can see on the charge tab there is listview ,there is several block one below the other ,in the screenshot you can see 1 , with the truck number and charge 1 and charge 2 ,and below that there is another block items with same view as block 1.
What i need to do ,charge(i.e below LR No.) is coming from the webservice , there can be any number of charges , if there is 5 charges applied to truck number then it should be added below detention layout (i.e charge 2) .As (similiar to Charge 2 is added below charge 1)
BaseAdapter Class:
public class ApprovalAdapter extends BaseAdapter {
List<ApprovalPogo> list;
Context context;
LayoutInflater inflater;
public ApprovalAdapter( Context context,List<ApprovalPogo> list) {
this.list = list;
this.context = context;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
class Viewholder{
TextView truck_name;
TextView lr_no;
Button btn_approve;
Button btn_reject;
Button btn_approve_status_change;
Button btn_approve2;
Button btn_reject2;
Button btn_chnge_status_two;
TextView extra_height;
TextView detention;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final Viewholder viewholder;
if(convertView==null){
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.single_row_approvals, parent, false);
viewholder=new Viewholder();
viewholder.truck_name = (TextView) convertView.findViewById(R.id.appr_txt_truck);
viewholder.lr_no = (TextView) convertView.findViewById(R.id.appr_lrNo);
viewholder.extra_height = (TextView) convertView.findViewById(R.id.extra_height);
viewholder.detention = (TextView) convertView.findViewById(R.id.txt_detention);
viewholder.btn_approve=(Button) convertView.findViewById(R.id.approve_btn);
viewholder.btn_reject=(Button) convertView.findViewById(R.id.reject_btn);
viewholder.btn_approve_status_change = (Button) convertView.findViewById(R.id.status_change_btn);
viewholder.btn_approve2=(Button) convertView.findViewById(R.id.status_charge_two_approve_btn);
viewholder.btn_reject2=(Button) convertView.findViewById(R.id.status_charge_two_reject_btn);
viewholder.btn_chnge_status_two=(Button) convertView.findViewById(R.id.status_change_charge_two_btn);
viewholder.btn_approve.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String time=getTime();
viewholder.btn_approve.setVisibility(View.GONE);
viewholder.btn_reject.setVisibility(View.GONE);
viewholder.btn_approve_status_change.setVisibility(View.VISIBLE);
viewholder.btn_approve_status_change.setText("Accepted on "+time);
viewholder.btn_approve_status_change.setBackgroundResource(R.drawable.approval_change_status_backg);
}
});
viewholder.btn_reject.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String time=getTime();
viewholder.btn_reject.setVisibility(View.GONE);
viewholder.btn_approve.setVisibility(View.GONE);
viewholder.btn_approve_status_change.setVisibility(View.VISIBLE);
viewholder.btn_approve_status_change.setText("Rejected on "+time);
viewholder.btn_approve_status_change.setBackgroundResource(R.drawable.approval_reject_chng_status);
}
});
viewholder.btn_approve2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String time=getTime();
viewholder.btn_approve2.setVisibility(View.GONE);
viewholder.btn_reject2.setVisibility(View.GONE);
viewholder.btn_chnge_status_two.setVisibility(View.VISIBLE);
viewholder.btn_chnge_status_two.setText("Accepted on "+time);
viewholder.btn_chnge_status_two.setBackgroundResource(R.drawable.approval_change_status_backg);
}
});
viewholder.btn_reject2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String time=getTime();
viewholder.btn_reject2.setVisibility(View.GONE);
viewholder.btn_approve2.setVisibility(View.GONE);
viewholder.btn_chnge_status_two.setVisibility(View.VISIBLE);
viewholder.btn_chnge_status_two.setText("Rejected on "+time);
viewholder.btn_chnge_status_two.setBackgroundResource(R.drawable.approval_reject_chng_status);
}
});
convertView.setTag(viewholder);
}else{
viewholder=(Viewholder) convertView.getTag();
}
viewholder.truck_name.setText(list.get(position).getTruckName()) ;
viewholder.lr_no.setText(list.get(position).getLrNmbr()) ;
// viewholder.btn_approve_status_change.setText(list.get(position));
//
// for(int i=0;i<list.get(position).getApprovalSubListPogos().size();i++){
// viewholder.btn_approve_status_change.setText(list.get(position).getApprovalSubListPogos().get(i).getStatusChange()) ;
// viewholder.extra_height.setText(list.get(position).getApprovalSubListPogos().get(i).getHeight()) ;
// viewholder.detention.setText(list.get(position).getApprovalSubListPogos().get(i).getHeight()) ;
//
//
// }
Config.colorFont(context, null, viewholder.truck_name, null);
Config.colorFont(context, null, viewholder.lr_no, null);
Config.colorFont(context, null, viewholder.extra_height, null);
Config.colorFont(context, null, viewholder.detention, null);
Config.colorFont(context, null, null ,viewholder.btn_approve);
Config.colorFont(context, null, null, viewholder.btn_reject);
Config.colorFont(context, null, null, viewholder.btn_approve_status_change);
Config.colorFont(context, null, null, viewholder.btn_approve2);
Config.colorFont(context, null,null, viewholder.btn_reject2);
Config.colorFont(context, null,null, viewholder.btn_chnge_status_two);
return convertView;
}
#Override
public boolean areAllItemsEnabled()
{
return false;
}
#Override
public boolean isEnabled(int position)
{
return false;
}
public String getTime(){
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"+5.5));
Date currentLocalTime = cal.getTime();
System.out.println(currentLocalTime);
DateFormat date = new SimpleDateFormat("HH:mm a");
String localTime = date.format(Calendar.getInstance().getTime());
// date.setTimeZone(TimeZone.getTimeZone("GMT"));
// String localTime = date.format(currentLocalTime);
return localTime;
}
public void findDuplicate(){
for(int i=0;i<list.size();i++){
for(int j=i+1;j<list.size();j++){
if(list.get(j).getTruckName().equalsIgnoreCase(list.get(i).getTruckName())){
}
}
}
}
}
single_row_xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/truck_rounded_view"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/approval_header"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/appr_txt_truck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Truck MH01BQ4111"
android:layout_marginTop="#dimen/approval_margin"
android:layout_marginLeft="#dimen/approval_margin"
android:textSize="#dimen/approval_header_size"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textColor="#color/darkgray"
android:textStyle="bold" />
<TextView
android:id="#+id/appr_lrNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LR 788691"
android:layout_marginTop="#dimen/approval_margin"
android:layout_marginLeft="#dimen/approval_margin"
android:textSize="#dimen/approval_header_size"
android:layout_gravity="center_vertical"
android:gravity="center"
android:layout_marginBottom="#dimen/approval_rl_top"
android:textColor="#color/darkgray"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!--<View
android:layout_marginTop="#dimen/approval_margin"
android:layout_marginLeft="#dimen/approval_margin"
android:layout_marginRight="#dimen/approval_margin"
android:layout_width="match_parent"
android:layout_height="#dimen/approval_divider_height"
android:background="#color/white" />-->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_marginTop="#dimen/approval_rl_top"
android:layout_marginLeft="#dimen/approval_margin"
android:layout_marginRight="#dimen/approval_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/appr_charge_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Charge 1"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:textSize="#dimen/txt_approval_txt"
android:textColor="#color/white"
android:textStyle="bold" />
<Button
android:id="#+id/approve_btn"
android:layout_width="#dimen/approval_btn_width"
android:layout_height="#dimen/approval_btn_height"
android:background="#drawable/aprroval_aprrove_backg"
android:textColor="#color/white"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="#dimen/approval_padding_left"
android:clickable="true"
android:layout_alignParentRight="true"
android:textSize="#dimen/approval_text_size"
android:textStyle="bold"
android:text="APPROVE" />
<Button
android:visibility="gone"
android:id="#+id/status_change_btn"
android:layout_width="#dimen/approval_status_chnege_width"
android:layout_alignParentRight="true"
android:maxLines="2"
android:layout_height="#dimen/approval_btn_height"
android:background="#drawable/approval_change_status_backg"
android:gravity="center"
android:padding="#dimen/approval_margin"
android:textSize="#dimen/approval_text_size"
android:textStyle="bold"
android:textColor="#color/white"
android:text="Accepted on 3:00 PM" />
</RelativeLayout>
<RelativeLayout
android:layout_marginTop="#dimen/approval_rl_top"
android:layout_marginLeft="#dimen/approval_margin"
android:layout_marginRight="#dimen/approval_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/extra_height"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Extra Height - Rs 200"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:textSize="#dimen/txt_approval_txt"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#color/white"
android:textStyle="bold" />
<Button
android:id="#+id/reject_btn"
android:layout_width="#dimen/approval_btn_width"
android:layout_height="#dimen/approval_btn_height"
android:text="Reject"
android:textSize="#dimen/approval_text_size"
android:paddingLeft="#dimen/approval_padding_left"
android:gravity="center"
android:textColor="#color/white"
android:layout_alignParentRight="true"
android:background="#drawable/approval_reject_backg"
android:textStyle="bold"/>
</RelativeLayout>
<View
android:layout_marginTop="#dimen/approval_rl_top"
android:layout_marginLeft="#dimen/approval_margin"
android:layout_marginRight="#dimen/approval_margin"
android:layout_width="match_parent"
android:layout_height="#dimen/approval_divider_height"
android:background="#color/white" />
<RelativeLayout
android:layout_marginTop="#dimen/approval_rl_top"
android:layout_marginLeft="#dimen/approval_margin"
android:layout_marginRight="#dimen/approval_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/charge_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Charge 2 "
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:textSize="#dimen/txt_approval_txt"
android:textColor="#color/white"
android:textStyle="bold" />
<Button
android:id="#+id/status_charge_two_approve_btn"
android:layout_width="#dimen/approval_btn_width"
android:layout_height="#dimen/approval_btn_height"
android:background="#drawable/aprroval_aprrove_backg"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#color/white"
android:layout_alignParentRight="true"
android:paddingLeft="#dimen/approval_padding_left"
android:textSize="#dimen/approval_text_size"
android:textStyle="bold"
android:text="APPROVE" />
<Button
android:visibility="gone"
android:id="#+id/status_change_charge_two_btn"
android:layout_width="#dimen/approval_status_chnege_width"
android:layout_alignParentRight="true"
android:maxLines="2"
android:layout_height="#dimen/approval_btn_height"
android:background="#drawable/approval_change_status_backg"
android:textStyle="bold"
android:textColor="#color/white"
android:gravity="center"
android:paddingLeft="#dimen/approval_padding_left"
android:textSize="#dimen/approval_text_size"
android:text="Rejected on 3:00 PM" />
</RelativeLayout>
<RelativeLayout
android:layout_marginTop="#dimen/approval_rl_top"
android:layout_marginLeft="#dimen/approval_margin"
android:layout_marginRight="#dimen/approval_margin"
android:layout_marginBottom="#dimen/approval_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt_detention"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Detention - Rs 200"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:textSize="#dimen/txt_approval_txt"
android:textColor="#color/white"
android:textStyle="bold" />
<Button
android:id="#+id/status_charge_two_reject_btn"
android:layout_width="#dimen/approval_btn_width"
android:layout_height="#dimen/approval_btn_height"
android:gravity="center"
android:layout_alignParentRight="true"
android:text="REJECT"
android:textColor="#color/white"
android:background="#drawable/approval_reject_backg"
android:textStyle="bold"
android:paddingLeft="#dimen/approval_padding_left"
/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
please use Expandable ListView to better use.
for more information and example about Expandable listview
You are not supposed to put scrollable things into scrollable things, and you usually shouldn't need to in the first place. This won't work most of the time.
How to get onclick of a view in custom dialog in an activity in android?
My XML is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/default_green"
android:orientation="vertical" >
<TextView
android:id="#+id/tvSetNotificationsHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:text="Set Notifications On"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white" />
<RadioButton
android:id="#+id/rbFriendRequest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Friend Request"
android:textColor="#android:color/white" />
<RadioButton
android:id="#+id/rbMessages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Messages"
android:textColor="#android:color/white" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:onClick="saveSetNotificationsDialog"
android:text="Save" />
</LinearLayout>
My code is:
public void showSetNotificationsDialog(View v) {
dialog = new Dialog(Activity_Settings.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_setnotificationsdialog);
rbFriendRequest = (RadioButton) findViewById(R.id.rbFriendRequest);
rbMessages = (RadioButton) findViewById(R.id.rbMessages);
dialog.show();
}
I am able to show dialog view but no able to get on click of dialog save button in activity class. Error was no method found exception.
use instance of dialog for findViewById()
Button declineButton = (Button) dialog.findViewById(R.id.declineButton);
declineButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
use as following code
dialog = new Dialog(Activity_Settings.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
View view = View.inflate(getActivity(), R.layout.dialog_setnotificationsdialog, null);
dialog.setContentView(view);
//always find your view view.findViewbyid
yourView= (RadioButton) view.findViewById(R.id.rbFriendRequest);
//then you can add on click listner to any of your view i.e.
yourView.setonClickListener(this);(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
I am trying to allow the user to put a ring on the circle on the screen and then press the larger button so that the circle goes to the next ring size.
Everything work fines when no ring is on the screen.
However when a ring it on the screen no other touches are called and the buttons and the seekbar does not work.
I'm new in android and i haven't came across this requirement before. Is there a way I can allow multi-touch gestures on the activity or a way to ignore touches on that specific layout?
XML File
<?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:background="#color/White"
android:splitMotionEvents="false"
>
<TextView
android:id="#+id/us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<TextView
android:id="#+id/uklbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="UK Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<TextView
android:id="#+id/uk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/uklbl"
android:layout_alignBottom="#+id/uklbl"
android:layout_toRightOf="#+id/uklbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<ImageView
android:id="#+id/ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/uslbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/uk"
android:gravity="left"
android:padding="#dimen/standard_margin"
android:text="US Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<SeekBar
android:id="#+id/seekbar"
android:progressDrawable="#drawable/red_scrubber_progress"
android:thumb="#drawable/red_scrubber_control"
android:max="8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/divider" />
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uklbl"
android:layout_marginTop="18dp"
android:background="#color/pressed_gemporia" />
<TextView
android:id="#+id/sizes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="#dimen/standard_margin"
android:layout_below="#+id/seekbar"
android:text="TextView" android:textColor="#color/pressed_gemporia" />
<Button
android:id="#+id/right"
android:layout_width="100dp"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:background="#color/White"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/left"
android:text="Larger" />
<Button
android:id="#+id/left"
android:layout_width="100dp"
android:background="#color/White"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Smaller" />
<ImageView
android:id="#+id/ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ci"
android:layout_centerHorizontal="true"
android:src="#drawable/j" />
Java Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ring_sizes);
left = (Button)findViewById(R.id.left);
right = (Button)findViewById(R.id.right);
us = (TextView) findViewById(R.id.us);
uk = (TextView) findViewById(R.id.uk);
ci = (ImageView)findViewById(R.id.ci);
ring = (ImageView)findViewById(R.id.ring);
sizes.add(R.drawable.j);
sizes.add(R.drawable.l);
sizes.add(R.drawable.n);
sizes.add(R.drawable.p);
sizes.add(R.drawable.r);
sizes.add(R.drawable.t);
sizes.add(R.drawable.v);
sizes.add(R.drawable.x);
sizes.add(R.drawable.z);
USsizes.add("5");
USsizes.add("6");
USsizes.add("7");
USsizes.add("8");
USsizes.add("9");
USsizes.add("10");
USsizes.add("11");
USsizes.add("12");
USsizes.add("13");
UKsizes.add("J-K");
UKsizes.add("L-M");
UKsizes.add("N-O");
UKsizes.add("P-Q");
UKsizes.add("R-S");
UKsizes.add("T-U");
UKsizes.add("V-W");
UKsizes.add("X-Y");
UKsizes.add("Z+");
color = (getBaseContext().getResources().getColor(R.color.pressed_gemporia));
value = (TextView) findViewById(R.id.sizes);
seekbar = (SeekBar) findViewById(R.id.seekbar);
seekbar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
value.setText("UK Size : "+UKsizes.get(0) + " - US Size: " + USsizes.get(0));
setUpViews();
seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
ring.setImageResource(sizes.get(progress));
us.setText(USsizes.get(progress));
uk.setText(UKsizes.get(progress));
counter=progress;
value.setText("UK Size : "+UKsizes.get(progress) + " - US Size: " + USsizes.get(progress));
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
}
public void setUpViews(){
ring.setImageResource(sizes.get(counter));
us.setText(USsizes.get(counter));
uk.setText(UKsizes.get(counter));
right.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(UKsizes.size()>counter+1){
ring.setImageResource(sizes.get(counter+1));
seekbar.setProgress(counter+1);
}
}
});
left.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(counter!=0){
ring.setImageResource(sizes.get(counter));
seekbar.setProgress(counter-1);
} }
});
}
}
There is a way to ignore touches in particular layout,for that you should add
android:splitMotionEvents="false"
in your layout . You can refer answers from thie following link
https://stackoverflow.com/questions/12777435/disable-multi-finger-touch-in-my-app
I am new to android world and am working on dialog and in that I am trying to create a text view, button and imageview, but it is neither showing me error nor textview or imageview. It is showing a button. Here is the image:
.
But i am want to display my dialogue as follows
My xml file is as follows ....
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".AddFriendsCustomActivity">
<ImageView
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/submit_dialog"
android:layout_alignParentRight="true"
android:layout_marginRight="37dp"
android:contentDescription="#string/add_Friend"
android:src="#drawable/add" />
<Button
android:id="#+id/submit_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="64dp"
android:layout_toLeftOf="#+id/add"
android:text="#string/submit" />
<EditText
android:id="#+id/writename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/add"
android:layout_marginRight="17dp"
android:layout_toLeftOf="#+id/add"
android:ems="10" />
</RelativeLayout>
I am calling it in java file as follows
dialog = new Dialog(context);
LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = li.inflate(R.layout.activity_add_friends_dialog, null, false);
dialog.setContentView(view);
dialog.setCancelable(true);
//dialog.setContentView(R.layout.activity_add_friends_dialog);
//dialog.setTitle("Add Friends");
add= (ImageView) dialog.findViewById(R.id.add);
friends1 = (TextView) dialog.findViewById(R.id.writename);
submit_dialog = (Button) dialog.findViewById(R.id.submit_dialog);
add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try {
friendsCount++;
Log.d("addFriendsActivity", "ashish comes here ");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
submit_dialog.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(AddFriendsActivity.this, DetailsFriendsActivity.class);
startActivity(i);
}
});
dialog.show();
After some google I understand that the issues might be in r.java or you have imported android .r but i have not done any thing in this ..
Thanks in advance.... :)
<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:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >
<EditText
android:id="#+id/writename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
<ImageView
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<Button
android:id="#+id/submit_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
There is no error in your java code. Its perfect you have just change your xml. Use this.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".AddFriendsCustomActivity" >
<EditText
android:id="#+id/writename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="24dp"
android:ems="10" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/writename"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/writename"
android:contentDescription="Add Friend"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/submit_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/writename"
android:layout_below="#+id/add"
android:layout_marginRight="46dp"
android:text="Submit" />
</RelativeLayout>
For your xml I think it should look like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/add_btn" />
<ImageButton
android:id="#+id/add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/add_btn"
android:background="#null" />
<Button
android:id="#+id/submit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/my_edit_text"
android:text="Submit" />
</RelativeLayout>
Be aware that there can be some typo mistakes, because I didn't compile that code, and you should change your real variables. And create your AlertDialog like this:
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MyActivity.this);
View mView = mInflater.inflater(R.layout.my_layout, null, false);
EditText mEdit = (EditText) mView.findViewById(R.id.my_edit_text);
ImageButton mImageBtn = (ImageButton) mView.findViewById(R.id.add_btn);
Button mSubmit = (Button) mView.findViewById(R.id.submit_btn);
mBuilder.setView(mView);
AlertDialog mAlert = mBuilder.create();
mAlert.show();
Using AlertDialog.Builder instead of Dialog is lot more easier for your situation (at least in my opinion). And you can add your Submit Button to your AlertDialog as default positive button.
Hope this helps you.
Look at your code i think
add= (ImageView) dialog.findViewById(R.id.add);
friends1 = (TextView) dialog.findViewById(R.id.writename);
as
add= (ImageView) view.findViewById(R.id.add);
friends1 = (EditText) view.findViewById(R.id.writename);
That should work.
Try this..
final Dialog dialog = new Dialog(AddFriendsActivity.this);
dialog.setContentView(R.layout.activity_add_friends_dialog);
dialog.setCanceledOnTouchOutside(true);
add= (ImageView) dialog.findViewById(R.id.add);
EditText friends1 = (EditText) dialog.findViewById(R.id.writename);
submit_dialog = (Button) dialog.findViewById(R.id.submit_dialog);
add.setOnClickListener(new OnClickListener() {
//#Override
#SuppressWarnings({ "unchecked", "rawtypes" })
#SuppressLint("NewApi")
public void onClick(View v) {
friendsCount++;
//TextView textview = new TextView(context);
//textview.setId(friendsCount);
//final RelativeLayout.LayoutParams params= new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
//params.addRule(RelativeLayout.BELOW, friendsCount--);
//textview.setLayoutParams(params);
//textview.setVisibility(View.VISIBLE);
//relativelayout.addView(textview ,params);
Log.d("addFriendsActivity", "ashish comes here ");
}
});
submit_dialog.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(AddFriendsActivity.this, DetailsFriendsActivity.class);
startActivity(i);
}
});
dialog.show();
Your view is covered.
May be you can try to set your parent layout to Linearlayout, not RelativeLayout.