Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. I don't know but findBtView method cannot fint view and get null all the time.
  2.  
  3. File is in asset folder.
  4. Debbuger shows that file iread ok and I can create Employee object from file.
  5. Here is my layout with list:
  6.  
  7. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  8. xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  9. android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  10. android:paddingRight="@dimen/activity_horizontal_margin"
  11. android:paddingTop="@dimen/activity_vertical_margin"
  12. android:paddingBottom="@dimen/activity_vertical_margin"
  13. tools:context="com.miekinia.pawelziolkowski.rssreader1.EmployeesActivity">
  14.  
  15.  
  16. <ListView
  17. android:id="@+id/lvEmployees"
  18. android:layout_width="fill_parent"
  19. android:layout_height="wrap_content"
  20. android:listSelector="@drawable/big_card"></ListView>
  21. </RelativeLayout>
  22.  
  23.  
  24. Layout with item
  25.  
  26. <?xml version="1.0" encoding="utf-8"?>
  27. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  28. xmlns:card_view="http://schemas.android.com/apk/res-auto"
  29. android:orientation="vertical"
  30. android:layout_width="match_parent"
  31. android:layout_height="match_parent">
  32.  
  33. <android.support.v7.widget.CardView
  34. android:id="@+id/card_view"
  35. android:layout_width="fill_parent"
  36. android:layout_height="wrap_content"
  37. card_view:cardUseCompatPadding="true"
  38. card_view:cardElevation="3dp"
  39. card_view:cardCornerRadius="2dp">
  40.  
  41. <RelativeLayout
  42. android:layout_width="fill_parent"
  43. android:layout_height="wrap_content">
  44. <TextView
  45. android:id="@+id/tvEmployeeNameSurname"
  46. android:fontFamily="sans-serif-light"
  47. android:textColor="#BF360C"
  48. android:layout_marginLeft="5dp"
  49. android:textSize="22dp"
  50. android:layout_width="fill_parent"
  51. android:layout_height="wrap_content" />
  52.  
  53. <TextView
  54. android:id="@+id/tvemployeePosition"
  55. android:layout_below="@id/tvEmployeeNameSurname"
  56. android:layout_width="fill_parent"
  57. android:layout_height="wrap_content"
  58. android:layout_marginLeft="5dp"/>
  59.  
  60. <TextView
  61. android:id="@+id/tvemployeePhone"
  62. android:layout_below="@id/tvemployeePosition"
  63. android:layout_width="fill_parent"
  64. android:layout_height="wrap_content"
  65. android:layout_marginLeft="5dp"/>
  66. </RelativeLayout>
  67. </android.support.v7.widget.CardView>
  68.  
  69.  
  70. </LinearLayout>
  71.  
  72. activity
  73.  
  74.  
  75. package com.miekinia.pawelziolkowski.rssreader1;
  76. import android.app.Activity;
  77. import android.os.Bundle;
  78. import android.view.Menu;
  79. import android.view.MenuItem;
  80. import android.widget.ListView;
  81.  
  82. import org.json.JSONArray;
  83. import org.json.JSONException;
  84. import org.json.JSONObject;
  85.  
  86. import java.util.ArrayList;
  87.  
  88.  
  89. public class EmployeesActivity extends Activity {
  90. private ArrayList<Employee> employeesList=null;
  91. private JSONArray pracownicyJSONArrayFromJSON=null;
  92.  
  93. @Override
  94. protected void onCreate(Bundle savedInstanceState) {
  95. super.onCreate(savedInstanceState);
  96. setContentView(R.layout.activity_employees);
  97.  
  98. this.pracownicyJSONArrayFromJSON = Utylities.loadJSONToJSONArray("pracownicy.json", this);
  99.  
  100. employeesList= LoadListFromJSONArray();
  101. EmployeeAdapter ea = new EmployeeAdapter(employeesList);
  102.  
  103. ListView employeesListView = (ListView) findViewById(R.id.lvEmployees);
  104. employeesListView.setAdapter(ea);
  105. }
  106.  
  107. private ArrayList<Employee> LoadListFromJSONArray() {
  108. //int ArrayLength = this.pracownicyJSONArrayFromJSON.length();
  109. ArrayList<Employee> arrayList = new ArrayList<Employee>();
  110.  
  111. for (int i = 0;i<this.pracownicyJSONArrayFromJSON.length(); i++) {
  112. try {
  113. JSONObject jo = this.pracownicyJSONArrayFromJSON.getJSONObject(i);
  114.  
  115. Employee employee = new Employee();
  116. employee.setName(jo.getString("imie"));
  117. employee.setSurname(jo.getString("nazwisko"));
  118. employee.setPosition(jo.getString("stanowisko"));
  119. employee.setPhone(jo.getString("telefon"));
  120.  
  121. arrayList.add(employee);
  122. } catch (JSONException e) {
  123. e.printStackTrace();
  124. return arrayList;
  125. }
  126. }
  127.  
  128. return arrayList;
  129. }
  130.  
  131. @Override
  132. public boolean onCreateOptionsMenu(Menu menu) {
  133. // Inflate the menu; this adds items to the action bar if it is present.
  134. getMenuInflater().inflate(R.menu.menu_employees, menu);
  135. return true;
  136. }
  137.  
  138. @Override
  139. public boolean onOptionsItemSelected(MenuItem item) {
  140. // Handle action bar item clicks here. The action bar will
  141. // automatically handle clicks on the Home/Up button, so long
  142. // as you specify a parent activity in AndroidManifest.xml.
  143. int id = item.getItemId();
  144.  
  145. //noinspection SimplifiableIfStatement
  146. if (id == R.id.action_settings) {
  147. return true;
  148. }
  149.  
  150. return super.onOptionsItemSelected(item);
  151. }
  152. }
  153.  
  154. and adapter
  155.  
  156. package com.miekinia.pawelziolkowski.rssreader1;
  157.  
  158. import android.view.LayoutInflater;
  159. import android.view.View;
  160. import android.view.ViewGroup;
  161. import android.widget.BaseAdapter;
  162. import android.widget.TextView;
  163.  
  164. import java.util.ArrayList;
  165.  
  166. /**
  167. * Created by Ja on 2015-06-23.
  168. */
  169. public class EmployeeAdapter extends BaseAdapter
  170. {
  171. private ArrayList<Employee> employeesList;
  172. public EmployeeAdapter(ArrayList<Employee> employeesList) {
  173. this.employeesList = employeesList;
  174. }
  175.  
  176. @Override
  177. public int getCount() {
  178. return this.employeesList.size();
  179. }
  180.  
  181. @Override
  182. public Object getItem(int i) {
  183. return this.employeesList.get(i);
  184. }
  185.  
  186. @Override
  187. public long getItemId(int i) {
  188. return i;
  189. }
  190.  
  191. @Override
  192. public View getView(int i, View view, ViewGroup viewGroup) {
  193.  
  194. if (view == null) {
  195. LayoutInflater li = LayoutInflater.from(viewGroup.getContext());
  196. view = li.inflate(R.layout.employee_listview_item,viewGroup, false);
  197. }
  198.  
  199. TextView tvNameSurname = (TextView) viewGroup.findViewById(R.id.tvEmployeeNameSurname);
  200. tvNameSurname.setText(this.employeesList.get(i).getName() + " "+this.employeesList.get(i).getSurname());
  201.  
  202. TextView tvPosition = (TextView) viewGroup.findViewById(R.id.tvemployeePosition);
  203. tvPosition.setText(this.employeesList.get(i).getPosition());
  204.  
  205. TextView tvPhone = (TextView) viewGroup.findViewById(R.id.tvemployeePhone);
  206. tvPhone.setText(this.employeesList.get(i).getPhone());
  207.  
  208. return view;
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement