두 번째 listview 에 listfragment 지 않 스크롤
-
12-12-2019 - |
문제
나는 응용 프로그램을 만들었는 두 개의 조각과 양각이 있 listviews.첫 번째 listview 에 fragment1 은 스크롤 항목과도 강조 표시됩니다.하지만에 두 번째는 조각,listview 지 스크롤하고 심지어 항목을 받고 있지 않은 강조됩니다.할 수 있는 누군가가 나에게 문제가 무엇입니까?이 것은 여기에 나는 단지 이와 같은 조각 등을 모두 조각에서는 xml.어쨌든 그들은 둘 다 작동해야 또는 둘 모두 없기 때문에 하나이지 않습니다.그러나 이 문제가 발생하는 이유?
내 조각 클래스:
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>
해결책
그래서,당신의 코드는 것을 말하는 동 Fragment1 class
모두 조각의 main.xml
.나는 가정하여 활동 클래스가 포함 setContentView() 에 onCreate() 방법입니다.로 모두 각각 하나의 활동,가능성이 있는 것 하나만 볼가 강조했다.나는 단지 선택이지만,그것은 작동합니다. Just drag the listview in the second fragment,
오히려 당신은 수도 스크롤니다.당신이 당신의 두 번째 listview 을 강조 표시 내가 두려워,필요할 수 있는 별도의 xml 파일에(말 fragment1 및 fragment2)및 별도의 클래스에 대한 조각과를 얻을 초점에서는 이제까지 당신이 필요 첫번째 추가하여 다음과 같은 코드입니다.
listView1 = (ListView)findViewById(R.id.listView1);
listView1.requestFocus();
행운을 빕니다.
제휴하지 않습니다 StackOverflow