public class ListViewAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mLayoutInflater;
DatabaseHelper mydb;
int pos = 0;
enter code here
public ArrayList<Employee_info> mArrayList = new ArrayList<Employee_info>();
public ListViewAdapter(Context context,ArrayList<Employee_info> arrayList){
mContext=context;
mArrayList=arrayList;
mLayoutInflater=LayoutInflater.from(mContext);
mydb = new DatabaseHelper(mContext);
}
enter code here
@Override
public int getCount() {
return mArrayList.size();
}
enter code here
@Override
public Object getItem(int position) {
return mArrayList.get(position);
}
enter code here
@Override
public long getItemId(int position) {
return position;
}
enter code here
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder=new ViewHolder();
View view=convertView;
if(view == null){
//view = mLayoutInflater.inflate(R.layout.list_view,parent,false);
view = mLayoutInflater.inflate(R.layout.list_view,null);
holder.txtName = (TextView)view.findViewById(R.id.txtName);
holder.txtCode = (TextView)view.findViewById(R.id.txtCode);
holder.txtStatus = (TextView)view.findViewById(R.id.txtStatus);
//// Start //////////////
Button b1 = (Button) view.findViewById(R.id.button1);
Button b2 = (Button) view.findViewById(R.id.button2);
Button b3 = (Button) view.findViewById(R.id.button3);
b1.setTag(position);
final Employee_info emp_info = mArrayList.get(position);
b2.setTag(position);
b3.setTag(position);
final ViewHolder finalHolder = holder;
b3.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
int x = (int) v.getTag();
/* if (itemPos.contains(v)) {
finalHolder.txtCode.setTextColor(Color.RED);
finalHolder.txtName.setTextColor(Color.RED);
finalHolder.txtStatus.setTextColor(Color.RED);
}
else {*/
if (mArrayList.get(x).getGet_status() != null) {
if (mArrayList.get(x).getGet_status().equals("Unpaid")) {
String upd1 = mArrayList.get(x).getGet_code();
String upd2 = mArrayList.get(x).getGet_name();
String upd3 = "Paid";
mydb.UpdateData(upd1, upd2, upd3);
// THis code for only catch Month, year, Employee ID, Status
Calendar cal=Calendar.getInstance();
SimpleDateFormat month_date = new SimpleDateFormat("MMM");
String month_name = month_date.format(cal.getTime());
int thisYear = Calendar.getInstance().get(Calendar.YEAR);
mydb.insertEmpSalary(upd1, month_name, String.valueOf(thisYear), upd3);
finalHolder.txtStatus.setTextColor(Color.GREEN);
ListViewAdapter.this.notifyDataSetChanged();
} else {
String upd1 = mArrayList.get(x).getGet_code();
String upd2 = mArrayList.get(x).getGet_name();
String upd3 = "Unpaid";
mydb.UpdateData(upd1, upd2, upd3);
finalHolder.txtStatus.setTextColor(Color.RED);
}
}
}
//}
});
b1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(final View position) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Confirm");
builder.setMessage("Are you sure?");
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try
{
pos = (int) position.getTag();
mydb.deleteData(mArrayList.get(pos).getGet_code());
mArrayList.remove(pos);
ListViewAdapter.this.notifyDataSetChanged();
Toast.makeText(mContext, mArrayList.get(pos).getGet_code() + " Employee is Delete", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
e.printStackTrace();
}
dialog.dismiss();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
b2.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
alert.setTitle("Alert Dialog With EditText"); //Set Alert dialog title here
alert.setMessage("Enter Your Code");
pos = (int) v.getTag();
LinearLayout layout = new LinearLayout(mContext);
layout.setOrientation(LinearLayout.VERTICAL);
final EditText input = new EditText(mContext);
input.setText(mArrayList.get(pos).getGet_code());
layout.addView(input);
final EditText input1 = new EditText(mContext);
input1.setText(mArrayList.get(pos).getGet_name());
layout.addView(input1);
final EditText input2 = new EditText(mContext);
input2.setText(mArrayList.get(pos).getGet_status());
layout.addView(input2);
alert.setView(layout);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try
{
String srt = input.getEditableText().toString();
Log.d("ccccccc", srt);
String upd1 = input.getText().toString();
String upd2 = input1.getText().toString();
String upd3 = input2.getText().toString();
/*String upd1 = mArrayList.get(pos).getGet_code();
String upd2 = mArrayList.get(pos).getGet_name();
String upd3 = mArrayList.get(pos).getGet_status();
Log.d("Code1",mArrayList.get(pos).getGet_code());
Log.d("Name1",mArrayList.get(pos).getGet_name());
Log.d("Status1",mArrayList.get(pos).getGet_status());*/
Log.d("Code",upd1);
Log.d("Name", upd2);
Log.d("Status", upd3);
boolean isUpdate = mydb.UpdateData(upd1, upd2, upd3);
ListViewAdapter.this.notifyDataSetChanged();
notifyDataSetChanged();
if (isUpdate == true)
{
Log.e("Update Complete", String.valueOf(isUpdate));
ListViewAdapter.this.notifyDataSetChanged();
Toast.makeText(mContext, srt + " Employee is Updated", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(mContext, srt + " Employee is not Updated", Toast.LENGTH_LONG).show();
}
}
catch(Exception e)
{
e.printStackTrace();
}
dialog.dismiss();
}
});
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
AlertDialog alertDialog = alert.create();
alertDialog.show();
}
});
view.setTag(holder);
} else {
holder=(ViewHolder)view.getTag();
}
Employee_info employee_info = mArrayList.get(position);
holder.txtName.setText(employee_info.getGet_name());
holder.txtCode.setText(employee_info.getGet_code());
holder.txtStatus.setText(employee_info.getGet_status());
return view;
}
private class ViewHolder{
private TextView txtName,txtCode,txtStatus;
public Button b1;
}
}
0
A
答えて
0
getViewで値を追加することはできません。アクティビティでやりましょう
+0
getviewの設定はどこですか..... 1.CustomAdapterページyaa 2.MainActiity。 私のコードの表示を太字で表示してください – user1785128
+0
plz help me ....私は試してみましたが、まだリフレッシュしていません。 – user1785128
関連する問題
- 1. 更新後、挿入トリガがSQL Serverの更新時に機能しないVB.net
- 2. jqueryのonload関数が更新時に機能しない
- 3. 変数の更新時にangular2 ngstyleが機能しない
- 4. Ajaxの更新が機能しない
- 5. taffydb更新が機能しない
- 6. スコア更新スクリプトが機能しない
- 7. 更新ステートメントが機能しない
- 8. Lyft更新トークンが機能しない
- 9. リサイクラービューの更新が機能しない
- 10. pymongoの更新が機能しない
- 11. Grid RowEditing - 更新が機能しない
- 12. ストアドプロシージャで更新が機能しない
- 13. 更新パネルが機能しないチェックボックス
- 14. モデルを変更した後、更新データベースが機能しない
- 15. PDO更新機能
- 16. ページが更新中にJquery 'click'が機能しない
- 17. Visual Studioを更新した後にGitが機能しない
- 18. PostmanがChromeを更新した後に機能しない
- 19. データベースの更新時にLiveDataのリストが更新されない
- 20. 永続性OneToManyリストが更新時に更新されない
- 21. anglejs - アレイの更新時にng-repeatが更新されない
- 22. テキストボックスがページ更新時に更新されないASP.net
- 23. $ scope更新時にngRepeatが更新されない
- 24. 更新時にデータが更新されないLaravel 5.2
- 25. jEditable&DataTables - 更新時にテーブルが更新されない
- 26. ファイヤーベースの更新時に反応コンポーネントが更新されない
- 27. JGraphTグラフの更新が正しく機能していない
- 28. 更新後にChrome Colspanが機能しない
- 29. Officeの更新後にVBA Excelシートメソッドが機能しない
- 30. javascriptの更新後にブートストラップトグルが機能しない
問題の説明を追加してください。 –
レコードを更新してからリストビューをリフレッシュしないとき...... レコードを更新するとホームページに戻り、再びリストビューページに移動する – user1785128