내 (주요 활동)에서 Button (1)을 만들었습니다. 버튼 (1)을 클릭하면 Custom ListView가 포함 된 AlertDialog (1)가 표시됩니다. 해당 Custom ListView에는 클릭 할 때 AlertDialog (2)가 표시되고 ImageView (Clickable)가 포함 된 Button이 있습니다. 내가 뭘 하려는지 ImageView 내 이미지를 어떻게 설정할 수 있습니다. 여기 내 코드입니다 : - 여기 내 버튼 (1)myAdapter의 AlertDialog에서 만든 ImageView에서 이미지를 어떻게 설정할 수 있습니까? 기본 어댑터를 사용하여 임
public void PayInvoice(View view){
String minAmount = null;
myDbHelper = new DBHelper(this);
try {
myDbHelper.createDataBase();
myDbHelper.openDataBase();
CustomerID = "1600050";
minAmount = myDbHelper.getMinAmountDue(CustomerID);
} catch (Exception e) {
e.getMessage();
}
myDbHelper.close();
if (TotalAmountET.getText().equals("") || TotalAmountET.getText().length() == 0) {
Toast.makeText(this, "PUT PAYMENT AMOUNT FIRST...", Toast.LENGTH_SHORT).show();
} else if (Float.parseFloat(minAmount) > Float.parseFloat(TotalAmountET.getText().toString())) {
Toast.makeText(this, "TOTAL AMOUNT IS NOT ENOUGH...", Toast.LENGTH_SHORT).show();
} else {
AlertDialog.Builder alertdialogbuilder = new AlertDialog.Builder(PaymentHeader.this);
LayoutInflater inflater = getLayoutInflater();
View alertLayout = inflater.inflate(R.layout.sales_invoice_list, null);
alertdialogbuilder.setView(alertLayout);
final ListView SalesInvoiceList = (ListView) alertLayout.findViewById(R.id.invoiceList);
final Button Cancel = (Button) alertLayout.findViewById(R.id.cancelBTN);
final Button PayInvoice = (Button) alertLayout.findViewById(R.id.payinvoiceBTN);
final AlertDialog alertDialog = alertdialogbuilder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
myDbHelper = new DBHelper(this);
try {
myDbHelper.createDataBase();
myDbHelper.openDataBase();
CustomerID = "1600050";
try {
invoiceLists = myDbHelper.retrieveInvoices(CustomerID);
customListView_invoiceList = new CustomListView_InvoiceList
(this, invoiceLists,Float.parseFloat(TotalAmountET.getText().toString()));
SalesInvoiceList.setAdapter(customListView_invoiceList);
} catch (Exception e) {
e.getMessage();
}
} catch (Exception e) {
e.getMessage();
}
Cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
PayInvoice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertPaymentLine();
}
});
}
}
CustomListView_InvoiceList.java의 OnClick을의 -
MainActivity.java이 내에 AlertDialog에있는 ListView를 채우는 방법이다 (1).
public class CustomListView_InvoiceList extends BaseAdapter {
private Context mContext;
private List<InvoiceList> invoiceLists;
private Float TotalPaymentAmount;
DBHelper myDbHelper;
List DeductionType;
private ArrayAdapter<String> DeductionTypeAdapter;
private final int requestCode = 20;
public CustomListView_InvoiceList(Context mContext, List<InvoiceList> invoiceLists, Float totalPaymentAmount) {
this.mContext = mContext;
this.invoiceLists = invoiceLists;
this.TotalPaymentAmount = totalPaymentAmount;
}
@Override
public int getCount() {
return invoiceLists.size();
}
@Override
public Object getItem(int position) {
return invoiceLists.get(position);
}
@Override
public long getItemId(int position) {
return invoiceLists.get(position).getId();
}
public static class ViewHolder {
CheckBox SelectInvoiceCB, PayFull, PayPartial;
TextView SalesInvoiceNo, InvoiceDate, InvoiceAmount, DueDate;
EditText TotalAmount;
LinearLayout adddeductionBTN;
ImageView CaptureForm;
}
@Override
public View getView(final int position, View view, ViewGroup viewGroup) {
//View v = View.inflate(mContext, R.layout.sales_invoice_custom,null);
final ViewHolder holder;
if(view == null)
{
view = View.inflate(mContext, R.layout.sales_invoice_custom,null);
holder = new ViewHolder();
holder.SelectInvoiceCB = (CheckBox) view.findViewById(R.id.selectInvoiceCB);
holder.SalesInvoiceNo = (TextView) view.findViewById(R.id.SINo);
holder.InvoiceDate = (TextView) view.findViewById(R.id.SIDate);
holder.InvoiceAmount = (TextView) view.findViewById(R.id.SIAmount);
holder.DueDate = (TextView) view.findViewById(R.id.SIdueDate);
holder.PayFull = (CheckBox) view.findViewById(R.id.SIFull);
holder.PayPartial = (CheckBox) view.findViewById(R.id.SIPartial);
holder.TotalAmount = (EditText) view.findViewById(R.id.SITotalAmount);
holder.adddeductionBTN = (LinearLayout) view.findViewById(R.id.adddeductionBTN);
holder.SalesInvoiceNo.setText(invoiceLists.get(position).getSales_Invoice_ID());
holder.InvoiceDate.setText(invoiceLists.get(position).getInvoice_Date());
holder.InvoiceAmount.setText(invoiceLists.get(position).getAmount_Due());
holder.DueDate.setText(invoiceLists.get(position).getDue_Date());
holder.PayFull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (holder.PayFull.isChecked()){
holder.PayPartial.setChecked(false);
}
}
});
holder.PayPartial.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (holder.PayPartial.isChecked()){
holder.PayFull.setChecked(false);
}
}
});
try {
if (TotalPaymentAmount >= Float.parseFloat(holder.InvoiceAmount.getText().toString())) {
holder.SelectInvoiceCB.setChecked(true);
holder.PayFull.setChecked(true);
holder.TotalAmount.setText(holder.InvoiceAmount.getText().toString());
TotalPaymentAmount = TotalPaymentAmount - Float.parseFloat(holder.InvoiceAmount.getText().toString());
} else {
if (TotalPaymentAmount < 1) {
holder.TotalAmount.setText("0.00");
} else {
holder.SelectInvoiceCB.setChecked(true);
holder.PayPartial.setChecked(true);
holder.TotalAmount.setText(String.valueOf(TotalPaymentAmount));
TotalPaymentAmount = TotalPaymentAmount - Float.parseFloat(holder.InvoiceAmount.getText().toString());
Log.e("","Remaining Payment Amount: " + String.valueOf(TotalPaymentAmount));
}
}
} catch (Exception e) {
e.getMessage();
}
holder.adddeductionBTN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertdialogbuilder = new AlertDialog.Builder(mContext);
//LayoutInflater inflater = getLayoutInflater();
View alertLayout = LayoutInflater.from(mContext).inflate(R.layout.deduction_list,null);
alertdialogbuilder.setView(alertLayout);
final Spinner TypesOfDeduction = (Spinner) alertLayout.findViewById(R.id.typeOfDeduction);
final EditText DeductionRemarks = (EditText) alertLayout.findViewById(R.id.deductionRemarks);
final EditText DeductionAmount = (EditText) alertLayout.findViewById(R.id.deductionAmount);
final CheckBox DeductionWithForm = (CheckBox) alertLayout.findViewById(R.id.withForm);
holder.CaptureForm = (ImageView) alertLayout.findViewById(R.id.captureForm);
final Button Cancel = (Button) alertLayout.findViewById(R.id.cancelBTN);
final Button AddDeduction = (Button) alertLayout.findViewById(R.id.adddeductionBTN);
final AlertDialog alertDialog = alertdialogbuilder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
DeductionRemarks.setText(invoiceLists.get(position).getSales_Invoice_Line_ID());
myDbHelper = new DBHelper(mContext);
try {
myDbHelper.createDataBase();
myDbHelper.openDataBase();
DeductionType = myDbHelper.retrieveDeduction();
DeductionTypeAdapter = new ArrayAdapter<String>
(mContext, R.layout.spinner_single_line, DeductionType);
DeductionTypeAdapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
TypesOfDeduction.setAdapter(DeductionTypeAdapter);
TypesOfDeduction.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String ImageRequired = "";
myDbHelper = new DBHelper(mContext);
try {
myDbHelper.createDataBase();
myDbHelper.openDataBase();
ImageRequired = myDbHelper.getDeduction(TypesOfDeduction.getSelectedItem().toString(), "Image Required");
} catch (Exception e) {
e.getMessage();
}
myDbHelper.close();
if (ImageRequired.equals("YES")) {
DeductionWithForm.setEnabled(true);
Toast.makeText(mContext,
"Deduction Type: " + TypesOfDeduction.getSelectedItem().toString() +
" Image Required: " + ImageRequired, Toast.LENGTH_SHORT).show();
} else {
DeductionWithForm.setEnabled(false);
Toast.makeText(mContext,
"Deduction Type: " + TypesOfDeduction.getSelectedItem().toString() +
" Image Required: " + ImageRequired, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
DeductionWithForm.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (DeductionWithForm.isChecked()){
holder.CaptureForm.setEnabled(true);
} else {
holder.CaptureForm.setEnabled(false);
}
}
});
} catch (Exception e){
e.getMessage();
}
myDbHelper.close();
Cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
holder.CaptureForm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent photoCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
((Activity) mContext).startActivityForResult(photoCaptureIntent,requestCode);
}
});
}
});
view.setTag(holder);
}else{
holder = (ViewHolder) view.getTag();
}
return view;
}
}
도와주세요! 내 코드에 질문이 있으면 알려주십시오. 고맙습니다!
사용자 정의 대화 상자 클래스를 생성하고 요구 사항에 따라 인터페이스를 구현 –
죄송합니다. 설명해 주시겠습니까? –