나는 Activity와 3 개의 파편이 있습니다. 주요 활동의 하단에는 활성 조각을 전환하기위한 3 개의 버튼이 있습니다. 각 조각에는 ListView가 포함되어 있습니다. 개발하는 좋은 방법이라고 생각하십니까? 첫 번째 단편을 서버에서 다운로드하여 구문 분석하고 ListView에 요소를 추가하는 방법을 개발했지만 버튼을 눌러 Fragment2로 전환하면 첫 번째 단락이 유지됩니다.ListView가있는 조각은 유지됩니다.
이것은 주요 활동입니다. listView를 사용하는 Fragment는 일부 TextView와 하나의 ImageView에서 맞춤 어댑터를 사용하고 있습니다. listView를 제거하면 조각이 문제없이 바뀝니다.
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
public class Home extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_home);
}
public void selectFrag(View view) {
Fragment fr;
int stringTitleID = R.string.title_fragment1;
if(view == findViewById(R.id.imgBtn3))
{
fr = new FragmentThree();
stringTitleID = R.string.title_fragment3;
}
else if(view == findViewById(R.id.imgBtn2))
{
fr = new FragmentTwo();
stringTitleID = R.string.title_fragment2;
}
else
{
fr = new FragmentOne();
stringTitleID = R.string.title_fragment1;
}
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.fragment_place, fr);
fragmentTransaction.commit();
// I change the title in the top_bar
TextView textViewActivityTitle = (TextView) findViewById(R.id.textViewActivityTitle);
textViewActivityTitle.setText(getResources().getString(stringTitleID).toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
/*
* This functions clears the app cache. The json responses are stored in che cacheDir or cacheExternalDir.
* I clean them when the app is started. I only use the cache between the Fragments
*/
}
조각 솔루션이 좋은 것입니까? 왜 listview가있는 조각이 남았습니까? ListFragment를 사용해야합니까?
고마워요.
내 문제는 XML에있었습니다. android : id = "@ + id/fragment_place"대신 를 사용했습니다. –