Hellow, ListView'ı CardView içine uygulamıştım ama şimdi sahip olduğum sorun şu ki, CardView liste öğesi ekleme konusunda genişlemiyor. Biri bana yardım edebilir mi, sorunu nasıl çözebilirim? Ben stackoverflow farklı yayınlar aracılığıyla gitti ama benim kod aşağıda :(çözüm bulamıyorListView Inside CardView Tam uzunluğu gösteriliyor
// bu benim ListeGörünüm adaptör Sınıf
public class EmploymentHistoryAdapter extends BaseAdapter {
public ArrayList<EmploymentHistory> mEmploymentHistories;
private Context context;
public EmploymentHistoryAdapter(ArrayList<EmploymentHistory> mEmploymentHistories, Context context) {
this.mEmploymentHistories = mEmploymentHistories;
this.context = context;
}
@Override
public int getCount() {
return mEmploymentHistories.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = null;
EmploymentHistory empHistory = mEmploymentHistories.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.list_employee_history_row, parent, false);
} else {
v = convertView;
}
TextView hospital = (TextView) v.findViewById(R.id.hospital);
TextView department = (TextView) v.findViewById(R.id.department);
TextView startDate = (TextView) v.findViewById(R.id.startDate);
TextView endDate = (TextView) v.findViewById(R.id.endDate);
TextView hospitalName = (TextView) v.findViewById(R.id.hospitalName);
hospitalName.setText(empHistory.getHospital());
TextView departmentName = (TextView) v.findViewById(R.id.departmentName);
departmentName.setText(empHistory.getDepartment());
TextView startDate1 = (TextView) v.findViewById(R.id.startDate1);
startDate1.setText(empHistory.getStartDate());
TextView endDate1 = (TextView) v.findViewById(R.id.endDate1);
endDate1.setText(empHistory.getEndDate());
hospital.setVisibility(View.VISIBLE);
department.setVisibility(View.VISIBLE);
startDate.setVisibility(View.VISIBLE);
endDate.setVisibility(View.VISIBLE);
return v;
}
}
bu nerede ben kalabalık olduğu // olduğunu ListView
private void populateEmploymentHistoryList() {
listEmployeeHistory = (ListView) findViewById(R.id.listEmployeeHistory);
empHistory = dbHelper.getAllEmploymentHistory();
employmentHistoryAdapter = new EmploymentHistoryAdapter(empHistory,this);
listEmployeeHistory.setAdapter(employmentHistoryAdapter);
}
// Bu i ListView eklendi benim Düzen dosyasıdır ve ben list_row
için özel bir tasarıma sahiptir<android.support.v7.widget.CardView
android:id="@+id/employmentHistoryCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/employmentHistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#E0E0E0"
android:gravity="center"
android:text="Employment History"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="#4A148C" />
<TextView
android:id="@+id/addEmployment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/employmentHistory"
android:layout_marginTop="15dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableLeft="@drawable/ic_add"
android:drawablePadding="20dp"
android:drawableStart="@drawable/ic_add"
android:paddingLeft="30dp"
android:text="Add Employment"
android:textColor="#0e89d0" />
<ListView
android:id="@+id/listEmployeeHistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/addEmployment">
</ListView>
</RelativeLayout>
</android.support.v7.widget.CardView>
ya çalışır ama durum farklıdır. Farklı kullanıcı için aynı liste satırı olmayacaktır. Cevabınız sınırlı sayıda Liste öğesi varsa çalışır. –
Bana başka bir etkili çözüm önerebilir misin? Bu benim için işe yaramıyor –
Bir şey yapabilirsiniz. RecyclerView öğesinin her bir öğesi için gereksiniminize bağlı olarak yüksekliği dinamik olarak ayarlayın. Bu şekilde, ListView'leriniz, RecyclerView öğesindeki her öğenin gereksinimine göre bir yüksekliğe sahip olacaktır. –