0
ActivityGroups 대신 Fragments를 사용하기 위해 솔루션을 변경하려고했는데 그 위에있는 ListView에 따라 UI의 일부를 변경할 수있는 예제를 발견했습니다. 내가하고 싶은 일은 항목을 클릭하면 새로운 레이아웃 만 표시되도록 자체를 대체하는 ListView입니다. 이것이 가능합니까?보기를 조각으로 바꾸기
당신은 내가 사용하고 관련 코드의 예를 볼 수 아래 :
public class FragmentTestActivity extends FragmentActivity implements OnItemClickListener
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView l = (ListView) findViewById(R.id.number_list);
ArrayAdapter<String> magzTitles = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1,
new String[]{"Cupcake",
"TaberTHULE",
"Lite"});
l.setAdapter(magzTitles);
l.setOnItemClickListener(this);
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Fragment testFragment = new TestFragment(position++);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.the_frag, testFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
}
}
main.xml에를
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frags"
>
<ListView
android:id="@+id/number_list"
android:layout_width="150dp"
android:layout_height="match_parent"
/>
<fragment class="com.android.saket.fragments.TestFragment"
android:id="@+id/the_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
그래서 listview도 조각이어야합니까? – CodePrimate
나는 내가하려는 일을하는 예제를 찾을 수 없었습니다. 나에게 링크를 줄 수 있니? – CodePrimate
listview는 조각 일 수 있지만 listfragment에있을 수도 있고 그렇지 않아도됩니다. 다음은 올바른 소리로 연결되는 링크입니다. http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentHideShowSupport.html – Warpzit