Ich habe Tabellen Empfang und Protokolle und Tabelle Empfang has_many Protokolle. Also auf meiner LogsRecapitulation.class habe ich Gruppierungsprotokolle nach Sortier- und Bewertungsstufe (diese zwei Spalten stammen aus Tabellenprotokollen).Populating ExpandableListView aus der Datenbank - funktioniert nicht
Ich habe versucht, dies über ExpandableListView zu machen. Jede Gruppe von übergeordneten Elementen besteht aus Sort und Grade für jede Gruppe aus der Datenbank.
Kinder Elemente werden textViews für Protokolle zählen in Kind Element, Masse, Preis und einige berechnete Preis haben. Und es sollte wie folgt aussehen:
ich geschaffen habe expandableListView Layouts und Adapter. Aber jetzt habe ich Probleme mit Eltern- und Kindelementen aus der Datenbank zu füllen.
Hier ist mein Code, damit Sie sehen können, was ich bisher gemacht habe.
Dies ist expandableListAadapter Klasse:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<String>> listDataChild) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listDataChild;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.expendable_items, null);
}
TextView logsMass = (TextView) convertView.findViewById(R.id.exp_lis_mass);
TextView logsPrice = (TextView) convertView.findViewById(R.id.exp_lis_price);
TextView logsMassPrice = (TextView) convertView.findViewById(R.id.ext_lis_sum_price);
logsMass.setText(childText);
logsPrice.setText(childText);
logsMassPrice.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.expandable_group, null);
}
TextView logsSort = (TextView) convertView.findViewById(R.id.exp_gr_sort);
TextView logsGrade = (TextView) convertView.findViewById(R.id.exp_gr_grade);
TextView logsCount = (TextView) convertView.findViewById(R.id.exp_gr_logs_count);
logsSort.setText(headerTitle);
logsGrade.setText(headerTitle);
logsCount.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Und das ist meine logsRecapitulation Klasse:
public class LogsRecapitulation extends AppCompatActivity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expandable_layout);
//recieve RecepitID and query to group_by logs
final long forwardedId = (long) getIntent().getExtras().get(String.valueOf("recepitID"));
List<Logs> logsList = new Select().from(Logs.class).where("Receipt = " + forwardedId).groupBy("SortID, Grade").execute();
//get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
}
private void prepareListData() {
}
}
jetzt Mein Problem ist ExpendableListView mit Daten aus der Datenbank zu füllen. Hier sind meine Tabellenklassen:
//receipt table
@Table(name = "Receipt")
public class Receipt extends Model {
@Column(name="Place")
String place;
@Column(name="ShippingNumber")
String shippingNumber;
@Column(name="Warehouse")
String warehouse;
@Column(name="Carrier")
String carrier;
@Column(name="LicencePlate")
String licencePlate;
@Column(name = "Driver")
String driver;
@Column(name = "Customer")
String customer;
@Column(name= "DestWarehouse")
String destWarehouse;
@Column(name = "Employee")
String employee;
@Column(name = "PriceType")
String priceType;
@Column(name = "PriceCorrection")
Double priceCorrection;
@Column(name = "PriceCorrection2")
Double priceCorrection2;
@Column(name = "Supplier")
String supplier;
@Column(name = "CreatedAt")
Date createdAt;
}
//logs table
@Table(name = "Logs")
public class Logs extends Model {
@Column(name="PlateNumber")
String plate_number;
@Column(name="SortID")
String sort_id;
@Column(name="Grade")
String grade;
@Column(name = "Diametar")
double diameter;
@Column(name="Length")
double length;
@Column(name="CreatedAt")
Date createdAt;
@Column(name="Receipt")
Receipt receipt;
@Column(name = "Price")
Price price;
}
//price table
@Table(name = "Price")
public class Price extends Model {
@Column(name = "Sort")
String sort;
@Column(name = "Grade")
String grade;
@Column(name = "Diameter")
double diameter;
@Column(name = "LengthDG")
double lengthDG;
@Column(name = "LengthGG")
double lengthGG;
@Column(name = "StumpPriceKn")
double stumpPrice_kn;
@Column(name = "RoadPriceKn")
double roadPrice_kn;
}
Hinweis: Ich verwende ActiveAndroid.
Bitte, wenn jemand weiß, wie erweiterbare ListView von Datenbank zu füllen bitte helfen.
Frage: Was muss ich tun, um ExpandableListView erfolgreich aus der Datenbank zu füllen?
Vielen Dank für Ihre Antwort, werde ich versuchen, dies in ActiveAndroid implementieren und lassen Sie wissen, war ich erfolgreich. – RubyDigger19