Мой макет отлично работал, прежде чем я переключил его на использование фрагментов внутри DrawerLayout. После этого ListView в главном представлении при прокрутке копирует список.ListView ghosting при использовании DrawerLayout с фрагментами
Прокрутка содержимого ListView, но копия первой страницы остается на экране. Я регистрирую отладочные сообщения, и нет второй копии созданного списка, а вторая копия данных, отправленных с адаптера, отсутствует.
Схема для деятельности использует DrawerLayout с фрагментами перед переключением на фрагментах он работал отлично.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="400dp"
android:layout_height="800dp">
<!-- The main content view -->
<fragment android:name="com.nosweatbudgets.receipts.ReceiptsFragment"
android:id="@+id/receipts_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- The navigation drawer -->
<fragment android:name="com.nosweatbudgets.navigate.NavigateFragment"
android:id="@+id/navigate_fragment"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
/>
</android.support.v4.widget.DrawerLayout>
Классы фрагментов очень просты.
ReceiptFragment's onCreateView выглядит следующим образом.
View view = inflater.inflate(R.layout.receipts, container, false);
_adapter = new ReceiptsAdapter(inflater);
ListView list = (ListView) view.findViewById(R.id.receipt_list);
list.setAdapter(_adapter);
_adapter.Refresh();
return view;
NavigateFragment's onCreateView в основном то же самое с другим адаптером. Это ReceiptFragment, который является ореолом, в то время как NavigateFragment не призван. Тем не менее они могут в основном использовать тот же подход.
View view = inflater.inflate(R.layout.navigate, container, false);
_navigate = new NavigateAdapter(inflater);
// setup the list view for the side
ListView list = (ListView) view.findViewById(R.id.left_drawer);
list.setAdapter(_navigate);
_navigate.Refresh();
return view;
Для вышеуказанных классов фрагментов я использую следующие макеты.
receipts.xml
выглядит следующим образом.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/receipt_list"/>
</RelativeLayout>
navigate.xml
выглядит следующим образом.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:background="#EEEEEE"/>
</RelativeLayout>
Выдвинуть навигационное меню listview работает очень хорошо, но в главном квитанции listview есть проблема с ореолом.
Я полностью в тупике относительно того, что вызывает это.
EDIT:
Вот как представления создаются в ReceiptsAdapter
.
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null)
{
view = _inflater.inflate(R.layout.receipt, null);
}
TextView txt_vendor = (TextView) view.findViewById(R.id.receipt_vendor);
TextView txt_category = (TextView) view.findViewById(R.id.receipt_category);
TextView category_btn = (TextView) view.findViewById(R.id.category_btn);
Model receipt = _receipts.get(position);
int vendor_id = receipt.getAsInteger("smart_vendor_id");
int category_id = receipt.getAsInteger("smart_category_id");
if (_vendors.indexOfKey(vendor_id) >= 0)
{
txt_vendor.setText(_vendors.get(vendor_id));
}
else
{
txt_vendor.setText("Select Vendor");
}
if (_categories.indexOfKey(category_id) >= 0)
{
String cat = _categories.get(category_id);
txt_category.setText(cat);
category_btn.setText(Category.ShortTitle(cat));
category_btn.setBackgroundColor(Category.Color(cat));
//txt_category.setBackgroundColor(c);
}
else
{
txt_category.setText("Select Category");
category_btn.setText("N/A");
}
((TextView) view.findViewById(R.id.receipt_amount)).setText("$" + receipt.getAsString("amount"));
((TextView) view.findViewById(R.id.receipt_payment)).setText(receipt.getAsString("payment"));
((TextView) view.findViewById(R.id.receipt_date)).setText(receipt.getAsString("receipt_date"));
return view;
}
EDIT:
Это как активность для макета присоединяет фрагментов с помощью метода onCreate
.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// the layout uses fixed width/size, because the layout editor won't render match_parent.
// so I replace the layout parameters here with match_parent.
DrawerLayout layout = (DrawerLayout) getLayoutInflater().inflate(R.layout.main, null);
DrawerLayout.LayoutParams param = new DrawerLayout.LayoutParams(ViewGroup.LayoutParams
.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(param);
setContentView(layout);
// configure this activity
StyleActionBar();
// Add the fragments
getSupportFragmentManager().beginTransaction()
.add(R.id.navigate_fragment, new NavigateFragment())
.add(R.id.receipts_fragment, new ReceiptsFragment())
.commit();
}
Просто, чтобы подтвердить, что я вас правильно понимаю: когда вы нажимаете, чтобы открыть ящик, вы видите «NavigateFragment» на слое поверх «ReceiptsFragment»? Но когда ящик закрыт (перед открытием ящика или после его закрытия), вы просто видите «ReceiptsFragment»? – CommonsWare
можно ли увидеть метод getView из адаптера? также, если возможно, обновить. –
@CommonsWare hi ware, вы правы. NavigateFragment - скрытый вид, который вы выдвигаете слева, а ReceiptsFragment - это основное представление, которое всегда видно. – cgTag