O to moje layout-y:
activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/simplefragment"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
</FrameLayout>
timeline.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize="18dp"
android:id="@+id/timelineTextView"
android:gravity="left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timeTextView"
android:textSize="16dp"
android:gravity="center"
/>
</LinearLayout>
timetable_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:background="@color/grey"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/list"
/>
</LinearLayout>
I kod javy :
public class MainActivity extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
TimeTableFragment timeTableFragment = new TimeTableFragment();
fragmentTransaction.add(R.id.simplefragment,timeTableFragment);
fragmentTransaction.commit();*/
FragmentManager fragManager = getSupportFragmentManager();
Fragment theFragment = fragManager.findFragmentById(R.id.simplefragment);
if (theFragment == null) {
theFragment = new TimeTableFragment();
fragManager.beginTransaction()
.add(R.id.simplefragment, theFragment)
.commit();
}
}
}
public class TimeLineAdapter extends BaseAdapter {
private List<Example> text;
private Context context;
private LayoutInflater inflater = null;
public TimeLineAdapter( Context context,List<Example> text) {
this.text = text;
this.context = context;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return text.size();
}
@Override
public Object getItem(int position) {
return text.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView != null) {
holder = (ViewHolder) convertView.getTag();
} else {
convertView = inflater.inflate(R.layout.timeline, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
Example ex = (Example) getItem(position);
holder.timelineTextView.setText(ex.getTimelineText());
holder.timeTextView.setText(ex.getTime());
return convertView;
}
static class ViewHolder {
@Bind(R.id.timelineTextView)
TextView timelineTextView;
@Bind(R.id.timeTextView)
TextView timeTextView;
public ViewHolder(View convertView) {
ButterKnife.bind(this, convertView);
}
}
}
public class TimeTableFragment extends ListFragment {
ListView timeTableListView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View fragment = inflater.inflate(R.layout.timetable_fragment, container, false);
timeTableListView = (ListView) fragment.findViewById(android.R.id.list);
ArrayList<Example> list = new ArrayList<Example>();
list.add(new Example("Hiszpanski", "15min"));
TimeLineAdapter timeLineAdapter = new TimeLineAdapter(getActivity(), list);
timeTableListView.setAdapter(timeLineAdapter);
return fragment;
}
}
I mój problem jest taki, że listView umieszczone we fragmencie się nie wyświetla. Jakaś pomoc dlaczego tak się dzieje?
Z góry dzięki za odpowiedzi!