مدیریت کاربران مشترک
بروز خطا
امتیازات دریافتی
آپدیت RealTime اطلاعات سطر های ریسایکلر ویو
1 - Adapter ساخته شده را به implements RecyclerView.OnItemTouchListener می کنیم.
2- private GestureDetector gestureDetector;
اسنیپ
ReportActivityRecyclerAdapter+
switch (table) {
case "tbl_company":
Cursor cursor1 = G.database.rawQuery("Select " + table + ".* " + " FROM " + table, null);
getCompanyDataManual(table, cursor1);
CompanyRecyclerAdapter adapter1 = new CompanyRecyclerAdapter(companylist);
recyclerView.setAdapter(adapter1);
break;
case "tbl_employer":
Cursor cursor2 = G.database.rawQuery("Select " + table + ".* " + " FROM " + table, null);
getEmployerDataManual(table, cursor2);
EmployerRecyclerAdapter adapter2 = new EmployerRecyclerAdapter(employerList);
recyclerView.setAdapter(adapter2);
break;
case "tbl_customer":
final Cursor cursor3 = G.database.rawQuery("Select " + table + ".* " + " FROM " + table, null);
getCustomerManualData(table, cursor3);
final CustomerRecyclerAdapter adapter3 = new CustomerRecyclerAdapter(customerList);
recyclerView.setAdapter(adapter3);
recyclerView.addOnItemTouchListener(new CustomerRecyclerAdapter(getApplicationContext(), recyclerView, new CustomerRecyclerAdapter.ClickListener() {
@Override
public void onClick(View view, final int position) {
Toast.makeText(getApplicationContext(), position + " is selected successfully", Toast.LENGTH_SHORT).show();
G.handler.post(new Runnable() {
@Override
public void run() {
final Dialog dialog = new Dialog(ReportActivity.this);
dialog.setContentView(R.layout.dialog_update);
LinearLayout ln_update_customer = (LinearLayout) dialog.findViewById(R.id.ln_update_customer);
ln_update_customer.setVisibility(View.VISIBLE);
final EditText edt_customerName = (EditText) dialog.findViewById(R.id.edt_customerName);
final EditText edt_customerFamily = (EditText) dialog.findViewById(R.id.edt_customerFamily);
final EditText edt_customerTell = (EditText) dialog.findViewById(R.id.edt_customerTell);
final EditText edt_customerAddress = (EditText) dialog.findViewById(R.id.edt_customerAddress);
Button btn_updCustomer = (Button) dialog.findViewById(R.id.btn_updCustomer);
Button btn_updCancel = (Button) dialog.findViewById(R.id.btn_updCancel);
Log.i("LOG", "Customer id is : " + id);
String tbl = table.replace("tbl_", "");
Log.i("LOG", "table name is ::::::" + tbl);
String stringIdForWhere = tbl.replace(tbl, tbl + "Id");
Log.i("LOG", "Id is ::::::" + stringIdForWhere);
final int id = customerList.get(position).getCustomerId();
Cursor cursor = G.database.rawQuery("Select " + table + ".* " + " FROM " + table + " WHERE " + stringIdForWhere + " = " + id, null);
Log.i("LOG", "Row founded " + cursor.getCount());
while (cursor.moveToNext()) {
String customerName = cursor.getString(cursor.getColumnIndex("customerName"));
String customerFamily = cursor.getString(cursor.getColumnIndex("customerFamily"));
String customerTell = cursor.getString(cursor.getColumnIndex("customerTell"));
String customerAddress = cursor.getString(cursor.getColumnIndex("customerAddress"));
edt_customerName.setText("" + customerName);
edt_customerFamily.setText("" + customerFamily);
edt_customerTell.setText("" + customerTell);
edt_customerAddress.setText("" + customerAddress);
}
cursor.close();
btn_updCustomer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String customerName = edt_customerName.getText().toString();
String customerFamily = edt_customerFamily.getText().toString();
String customerTell = edt_customerTell.getText().toString();
String customerAddress = edt_customerAddress.getText().toString();
CustomerInfo customerInfo = new CustomerInfo();
customerInfo.setCustomerId(id);
customerInfo.setCustomerName(customerName);
customerInfo.setCustomerFamily(customerFamily);
customerInfo.setCustomerTell(customerTell);
customerInfo.setCustomerAddress(customerAddress);
dbHelper.update("tbl_customer", new String[]{"customerName", "customerFamily", "customerTell", "customerAddress"},
new Object[]{customerName, customerFamily, customerTell, customerAddress}, "customerId = '" + id + "'");
Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_SHORT).show();
getCustomerManualData(table, cursor3);
customerList.remove(position);
customerList.add(position, customerInfo);
final Cursor cursor3 = G.database.rawQuery("Select " + table + ".* " + " FROM " + table, null);
getCustomerManualData(table, cursor3);
CustomerRecyclerAdapter customerRecyclerAdapter = new CustomerRecyclerAdapter(customerList);
recyclerView.setAdapter(customerRecyclerAdapter);
dialog.dismiss();
}
});
btn_updCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
}
@Override
public void onLongClick(View view, int position) {
}
}));
break;
case "tbl_goods":
Cursor cursor4 = G.database.rawQuery("Select " + table + ".* " + " FROM " + table, null);
getGoodsDataManual(table, cursor4);
GoodsRecyclerAdapter adapter4 = new GoodsRecyclerAdapter(goodsList);
recyclerView.setAdapter(adapter4);
break;
case "tbl_category":
Cursor cursor5 = G.database.rawQuery("Select " + table + ".* " + " FROM " + table, null);
getCategoryDataManual(table, cursor5);
CategoryRecyclerAdapter adapter5 = new CategoryRecyclerAdapter(categoryList);
recyclerView.setAdapter(adapter5);
break;
}
package project.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.vahid.theboys.R;
import java.util.ArrayList;
import project.struct.CustomerInfo;
public class CustomerRecyclerAdapter extends RecyclerView.Adapter<CustomerRecyclerAdapter.ViewHolder> implements RecyclerView.OnItemTouchListener {
private GestureDetector gestureDetector;
private ClickListener clickListener;
private ArrayList<CustomerInfo> list;
public CustomerRecyclerAdapter(ArrayList<CustomerInfo> list) {
this.list = list;
}
public void updatee(ArrayList<CustomerInfo> updaList) {
if (list != null) {
list.clear();
list.addAll(updaList);
} else {
list = updaList;
}
notifyDataSetChanged();
}
public void update(ArrayList<CustomerInfo> updaList) {
if (updaList == null || updaList.size() <= 0) {
return;
}
if (list != null && list.size() > 0)
list.clear();
list.addAll(updaList);
notifyDataSetChanged();
}
@Override
public CustomerRecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_customer_list, parent, false);
return new ViewHolder(itemView);
}
public void onBindViewHolder(ViewHolder holder, int position) {
CustomerInfo item = list.get(position);
holder.txt_customerCode.setText("" + item.getCustomerId());
holder.txt_customerName.setText("" + item.getCustomerName());
holder.txt_customerFamily.setText("" + item.getCustomerFamily());
holder.txt_customerAddress.setText("" + item.getCustomerAddress());
}
@Override
public int getItemCount() {
return list.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView txt_customerName;
TextView txt_customerFamily;
TextView txt_customerAddress;
TextView txt_customerCode;
public ViewHolder(View itemView) {
super(itemView);
txt_customerCode = (TextView) itemView.findViewById(R.id.txt_customerCode);
txt_customerName = (TextView) itemView.findViewById(R.id.txt_customerName);
txt_customerFamily = (TextView) itemView.findViewById(R.id.txt_customerFamily);
txt_customerAddress = (TextView) itemView.findViewById(R.id.txt_customerAddress);
}
}
public CustomerRecyclerAdapter(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
this.clickListener = clickListener;
this.list = list;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null) {
clickListener.onLongClick(child, recyclerView.getChildPosition(child));
}
}
});
}
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
clickListener.onClick(child, rv.getChildPosition(child));
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
public interface ClickListener {
void onClick(View view, int position);
void onLongClick(View view, int position);
}
}
length : 0
words : 0
lines : 0
حقوق مادی و معنوی تمامی آثار و محتویات عرضه شده در این وب سایت، متعلق به شرکت «فوژان رسانه ایده هوشمند» و پدیدآورندگان آثار بوده و حسب مورد دارای مجوز از مراجع ذی صلاح می باشد.
کپی برداری از مطالب این سایت حتی با ذکر منبع جایز نیست.
ویرایش
پیام