我創建了一個應用程序,其中有兩個片段,兩個片段中都有listviews。 fragment1中的第一個listview正在滾動,並且項目也被突出顯示。但在第二個片段中,listview不會滾動,甚至項目也不會突出顯示。有人能告訴我什麼是問題嗎?這裏的東西是我只是檢查了這一點,把相同的片段類放入xml中的兩個片段。要麼他們都應該工作,要麼兩者都不應該,因爲一個人與另一個人沒有區別。但爲什麼會出現這個問題?listfragment中的第二個listview不滾動
我的片段類:
public class Fragment1 extends ListFragment{
String[] countries = new String[] {
"India",
"Pakistan",
"Sri Lanka",
"China",
"Bangladesh",
"Nepal",
"Afghanistan",
"North Korea",
"South Korea",
"Japan"
};
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment1,container,false);
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,countries);
setListAdapter(adapter);
}
public void onListItemClick(ListView parent, View v,int position, long id)
{
Toast.makeText(getActivity(), "You have selected "+countries[position], Toast.LENGTH_SHORT).show();
}
}
的main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<fragment
android:name="com.example.listfragmentexample.Fragment1"
android:id="@+id/fragment1"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="200dp" />
<fragment
android:name="com.example.listfragmentexample.Fragment1"
android:id="@+id/fragment2"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="300dp"/>
</LinearLayout>
fragment1.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
</LinearLayout>
是的。謝謝。當我嘗試滾動第二個列表視圖時,即使將光標置於其上並單擊其項目,它也不會滾動。所以,我感到困惑,但拖動作品。沒關係。好吧,會嘗試實施您的建議,以突出顯示另一個。 – Korhan