Здравствуйте! Пытаюсь заполнить данными фрагмент листвью. Программа запускается корректно, но когда открываю фрагмент там нет данных(показывает экран с моим TextView и надписью "Нет данных"), при дебаге видно, что пустой сам листвью, т.е. в адаптор данные поступили. Посмотрите код пожалуйста.
public class MyEmployeFragment extends Fragment {
MyTask task;
String employer_id;
String employer_name;
String str=null;
// имена атрибутов для Map
final String ATTRIBUTE_ID = "p_id";
final String ATTRIBUTE_NAME = "p_name";
ListView listView;
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
task = new MyTask();
task.execute();
// Creating view correspoding to the fragment
View v = inflater.inflate(R.layout.my_employe, container, false);
// Updating the action bar title
getActivity().getActionBar();
String[] userId = {"1","2","3"};
String[] userName = {"Nadezhd","Vasya", "hardcore"};
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(
userId.length);
Map<String, Object> m;
for (int i = 0; i < userId.length; i++) {
m = new HashMap<String, Object>();
m.put(ATTRIBUTE_ID, userId[i]);
m.put(ATTRIBUTE_NAME, userName[i]);
data.add(m);
}
// массив имен атрибутов, из которых будут читаться данные
String[] from = {ATTRIBUTE_ID, ATTRIBUTE_NAME};
// массив ID View-компонентов, в которые будут вставлять данные
int[] to = {R.id.tw_employe_id, R.id.tw_employe_name};
// создаем адаптер
SimpleAdapter sAdapter = new SimpleAdapter(getActivity(), data, R.layout.list_item_employee,
from, to);
// определяем список и присваиваем ему адаптер
listView = (ListView) v.findViewById(R.id.lv_employee_list);
listView.setAdapter(sAdapter);
return v;
}
}
list _ item _ employe.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="20dp"
android:id="@+id/tw_employe_id" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tw_employe_name"
android:paddingLeft="20dp" />
</LinearLayout>
my _ employe .xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lv_employee_list"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:layout_marginTop="150dp"
android:id="@+id/tw_employe_name"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/empty">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=""
android:layout_marginLeft="14dp"
android:id="@+id/tw_employe_id"
/>
</LinearLayout>