i have simple project that have list view when any one click on any item on list view open in single window by fragment the problem is that i want to replace my fragment with on of this tabs fragment on this project http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/
i put my mainactivty class in switch case but it get to me this error in first picture i try to import import android.support.v4.app.Fragment but also the same promplem
this is the clases of my project ....Main2Activity class
public class Main2Activity extends AppCompatActivity implements fragmentA.comunicatir
{
fragmentA f1;
fragmentB f2;
FragmentManager manegaer;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
manegaer=getSupportFragmentManager();
f1=(fragmentA)manegaer.findFragmentById(R.id.fragment1);
f1.setcomunicatir(this);
}
@Override
public void respned(int index){
f2=(fragmentB)manegaer.findFragmentById(R.id.fragment2);
if(f2!=null&&f2.isVisible()){
f2.cahngedata(index);
}else{
Intent intent=
new Intent(this,
AnotherActivity.class);
intent.putExtra("index",index);
startActivity(intent);
}
}
}
the another classes class fragmentA
public class fragmentA extends Fragment implements AdapterView.OnItemClickListener
{
ListView list;
comunicatir com;
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment1,container,false);
list=(ListView)view.findViewById(R.id.listView1);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.chapters, android.R.layout.simple_list_item_1);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
return view;
}
public void setcomunicatir (comunicatir comunicator)
{
this.com=comunicator;
}
@Override
public void onItemClick(AdapterView<?> adapterView, View veiw, int i, long l) {
com.respned(i);
}
public interface comunicatir
{
public void respned(int index);
}
}
public class fragmentB extends Fragment
{
TextView text;
TextView textView2;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment2, container, false);
//text = (TextView) view.findViewById(R.id.textView1);
//imgv=(ImageView) view.findViewById(R.id.imageView1);
textView2 =(TextView)view.findViewById(R.id.textView22);
return view;
}
public void cahngedata(int index)
{
/*String[] descrption =getResources().getStringArray(R.array.hadeith);
text.setText(descrption[index]);*/
String []Hadith=getResources().getStringArray(R.array.hadeith);
//imgv.setImageResource(img[index]);
textView2.setText(Hadith[index]);
//int []descrption =getResources().getIntArray(img[index]);
// imgv.setImageResource(descrption[index]);
/*text.setText(descrption[index]);
int arr[]=getResources().getIntArray(img[index]);
imgv.setImageResource(arr[index]);*/
}
}
public class AnotherActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.another);
Intent intent = getIntent();
int index= intent.getIntExtra("index", 0);
fragmentB f2= (fragmentB)
getFragmentManager().
findFragmentById(R.id.fragment2);
if (f2!=null)
f2.cahngedata(index);
}
}
the Another Activity class also have error in picture 2
1st issue: You just can't put an activity on a Tab, but you probably won't need the getItem() you can delete that method
2nd issue:
Replace:
fragmentB f2 = (fragmentB) ...
With:
fragment f2 = (Fragment) ...
go to the tab.class which u have problem in and change import android.app.Fragment; to import android.support.v4.app.Fragment;
it will run .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.