Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I don't know but findBtView method cannot fint view and get null all the time.
- File is in asset folder.
- Debbuger shows that file iread ok and I can create Employee object from file.
- Here is my layout with list:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
- 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="com.miekinia.pawelziolkowski.rssreader1.EmployeesActivity">
- <ListView
- android:id="@+id/lvEmployees"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:listSelector="@drawable/big_card"></ListView>
- </RelativeLayout>
- Layout with item
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:card_view="http://schemas.android.com/apk/res-auto"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v7.widget.CardView
- android:id="@+id/card_view"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- card_view:cardUseCompatPadding="true"
- card_view:cardElevation="3dp"
- card_view:cardCornerRadius="2dp">
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <TextView
- android:id="@+id/tvEmployeeNameSurname"
- android:fontFamily="sans-serif-light"
- android:textColor="#BF360C"
- android:layout_marginLeft="5dp"
- android:textSize="22dp"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
- <TextView
- android:id="@+id/tvemployeePosition"
- android:layout_below="@id/tvEmployeeNameSurname"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"/>
- <TextView
- android:id="@+id/tvemployeePhone"
- android:layout_below="@id/tvemployeePosition"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"/>
- </RelativeLayout>
- </android.support.v7.widget.CardView>
- </LinearLayout>
- activity
- package com.miekinia.pawelziolkowski.rssreader1;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.ListView;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- public class EmployeesActivity extends Activity {
- private ArrayList<Employee> employeesList=null;
- private JSONArray pracownicyJSONArrayFromJSON=null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_employees);
- this.pracownicyJSONArrayFromJSON = Utylities.loadJSONToJSONArray("pracownicy.json", this);
- employeesList= LoadListFromJSONArray();
- EmployeeAdapter ea = new EmployeeAdapter(employeesList);
- ListView employeesListView = (ListView) findViewById(R.id.lvEmployees);
- employeesListView.setAdapter(ea);
- }
- private ArrayList<Employee> LoadListFromJSONArray() {
- //int ArrayLength = this.pracownicyJSONArrayFromJSON.length();
- ArrayList<Employee> arrayList = new ArrayList<Employee>();
- for (int i = 0;i<this.pracownicyJSONArrayFromJSON.length(); i++) {
- try {
- JSONObject jo = this.pracownicyJSONArrayFromJSON.getJSONObject(i);
- Employee employee = new Employee();
- employee.setName(jo.getString("imie"));
- employee.setSurname(jo.getString("nazwisko"));
- employee.setPosition(jo.getString("stanowisko"));
- employee.setPhone(jo.getString("telefon"));
- arrayList.add(employee);
- } catch (JSONException e) {
- e.printStackTrace();
- return arrayList;
- }
- }
- return arrayList;
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_employees, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- and adapter
- package com.miekinia.pawelziolkowski.rssreader1;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.TextView;
- import java.util.ArrayList;
- /**
- * Created by Ja on 2015-06-23.
- */
- public class EmployeeAdapter extends BaseAdapter
- {
- private ArrayList<Employee> employeesList;
- public EmployeeAdapter(ArrayList<Employee> employeesList) {
- this.employeesList = employeesList;
- }
- @Override
- public int getCount() {
- return this.employeesList.size();
- }
- @Override
- public Object getItem(int i) {
- return this.employeesList.get(i);
- }
- @Override
- public long getItemId(int i) {
- return i;
- }
- @Override
- public View getView(int i, View view, ViewGroup viewGroup) {
- if (view == null) {
- LayoutInflater li = LayoutInflater.from(viewGroup.getContext());
- view = li.inflate(R.layout.employee_listview_item,viewGroup, false);
- }
- TextView tvNameSurname = (TextView) viewGroup.findViewById(R.id.tvEmployeeNameSurname);
- tvNameSurname.setText(this.employeesList.get(i).getName() + " "+this.employeesList.get(i).getSurname());
- TextView tvPosition = (TextView) viewGroup.findViewById(R.id.tvemployeePosition);
- tvPosition.setText(this.employeesList.get(i).getPosition());
- TextView tvPhone = (TextView) viewGroup.findViewById(R.id.tvemployeePhone);
- tvPhone.setText(this.employeesList.get(i).getPhone());
- return view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement