我的应用中有一个微调器,您可以在其中选择类别和子类别。 它在过去工作得很完美,但由于我在应用程序中做了很多修改,旋转器不再滚动,不仅仅是一个微调器,而是这个布局中的所有微调器(抽屉菜单)。
这是包含微调器的右侧菜单抽屉的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:rsb="http://schemas.android.com/apk/res-auto"
android:id="@+id/rightadvancedsearch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Grey"
android:gravity="center"
tools:context="com.chno.v1.Home">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="50dp"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="16dp">
<RelativeLayout
android:id="@+id/AllCat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:paddingBottom="16dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/query"
android:layout_width="match_parent"
android:layout_height="52dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:backgroundTint="@color/Blue"
android:drawableLeft="@android:drawable/ic_menu_search"
android:ems="10"
android:hint="Search"
android:inputType="textPersonName"
android:paddingLeft="5dp"
android:textColor="@color/Black"
android:textColorHint="@color/GreyDark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="6dp"
android:text="@string/Category"
android:textColor="@color/Blue"/>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="40dp"
android:textColor="@color/Blue" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/AllCat"
android:paddingBottom="16dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="6dp"
android:text="@string/Location"
android:textColor="@color/Blue" />
<TextView
android:id="@+id/textView28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/SelectCity" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!--
<CheckBox
android:id="@+id/nearby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Nearby" />-->
<CheckBox
android:id="@+id/checkNearby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Nearby" />
<TextView
android:id="@+id/currentray"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/defaultRay"
android:textAlignment="textEnd"
android:visibility="gone" />
</LinearLayout>
<com.yahoo.mobile.client.android.util.rangeseekbar.RangeSeekBar
android:id="@+id/rangeSeekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone"
rsb:absoluteMaxValue="100"
rsb:absoluteMinValue="1"
rsb:singleThumb="true" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/includeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/city"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
</LinearLayout>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="@color/BgLight">
<RelativeLayout
android:id="@+id/reset"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/GreyLight"
android:padding="10dp"
android:gravity="center">
<TextView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/Black"
android:layout_marginRight="12dp"
android:text="Ré-initialiser"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/Orange"
android:padding="10dp"
android:gravity="center">
<TextView
android:id="@+id/imageView3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/White"
android:textStyle="bold"
android:text="Recherche"/>
</RelativeLayout>
</LinearLayout>
这是微调器适配器:
package com.chno.v1;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
/**
* List view
*/
public class SpinnerAdapter extends ArrayAdapter<ItemDate> {
private int groupid;
private Activity context;
private ArrayList<ItemDate> list;
private LayoutInflater inflater;
public SpinnerAdapter(Activity context, int groupid, int id, ArrayList<ItemDate> list) {
super(context,id, list);
this.list = list;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.groupid = groupid;
}
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = inflater.inflate(groupid,parent,false);
ImageView imageView = (ImageView)itemView.findViewById(R.id.img);
ItemDate item = list.get(position);
if(item != null) {
if(item.getType() != null) {
if (item.getType().equals("sub_category")) {
imageView.setVisibility(View.GONE);
} else {
imageView.setImageResource(item.getImageId());
}
} else {
imageView.setImageResource(item.getImageId());
}
} else {
imageView.setImageResource(item.getImageId());
}
imageView.setImageResource(item.getImageId());
TextView textView = (TextView)itemView.findViewById(R.id.txt);
textView.setText(item.getText());
return itemView;
}
public View getDropDownView(int position, View convertView, ViewGroup
parent) {
return getView(position,convertView,parent);
}
}
问题是我可以从微调器中选择项目,但我无法向下滚动以获取更多项目。
以下是填充微调器的代码:
JSONObject result = config.getCategories();
Iterator<String> iter = result.keys();
while (iter.hasNext()) {
String key = iter.next();
try {
JSONObject cat = result.getJSONObject(key);
String category = cat.getString("n");
int drawable = helper.getCategoryDrawable(Integer.parseInt(key));
Log.e("" + category, "" + key);
list.add(new ItemDate("category", category, Integer.parseInt(key), drawable));
JSONObject subs = cat.getJSONObject("l");
Iterator<String> it2 = subs.keys();
while (it2.hasNext()) {
String sub_key = it2.next();
JSONObject sub_category = subs.getJSONObject(sub_key);
String name = sub_category.getString("n");
Log.e("FFROM LIST", "" + name);
list.add(new ItemDate("sub_category", name, Integer.parseInt(sub_key), Integer.parseInt(key), R.drawable.tool_icon_filter));
}
} catch (JSONException e) {
Log.e("JSONException", e.getMessage());
e.printStackTrace();
}
}
Spinner sp=(Spinner)findViewById(R.id.spinner1);
SpinnerAdapter adapter=new SpinnerAdapter((Activity) context, R.layout.sub_select_item, R.id.txt, list);
sp.setAdapter(adapter);
sp.setFocusable(true);
sp.setFocusableInTouchMode(true);
我该如何解决这个问题?感谢。