Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good day to all android enthusiast
I am developing an app that will require listviews and it's details shown when clicked.
I will like the list view and it's details to populated from a JSON or CSV reading from assets folder not from URL
Can anyone help with a tutorials that does this i have tried on my own but i can only code JSON parser from url

Kindly help
Posted
Comments
Suvendu Shekhar Giri 16-Jul-15 18:01pm    
Share the code you have tried.
Mohibur Rashid 16-Jul-15 20:11pm    
Put your text file to assets folder. And then access it
BufferedReader reader = new BufferedReader(
new InputStreamReader(getAssets().open("YourTextFile.txt")));
Do further processing
Member 10627743 17-Jul-15 7:52am    
I have been able to populate the listview through CSV and it's details displaying in a toast
Instead of displaying it in a toast how can it be displayed in an alert builder (dialog)
See my code below and full code here https://github.com/FoamyGuy/CSVListExample

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

/*
* Very basic Activity, the only things it does
* are get the ListView reference from our layout.
* Create an Adapter, set the Adapter to the ListView
* and handle the onItemClick events for when the user
* clicks on a row.
*/


public class MyActivity2 extends ActionBarActivity {

CSVAdapter mAdapter;
// Search EditText
EditText inputSearch;
private ArrayAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activity2);

//Lookup our ListView
ListView mlist = (ListView)findViewById(R.id.mlist);

//Create Adapter. The second parameter is required by ArrayAdapter
//which our Adapter extends. In this example though it is unused,
//so we'll pass it a "dummy" value of -1.
mAdapter = new CSVAdapter(this, -1);

//attach our Adapter to the ListView. This will populate all of the rows.
mlist.setAdapter(mAdapter);


/*
* This listener will get a callback whenever the user clicks on a row.
* The pos parameter will tell us which row got clicked.
*
* For now we'll just show a Toast with the state capital for the state that was clicked.
*/
mlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<!--?--> parent, View v, int pos,long id) {
Toast.makeText(v.getContext(), mAdapter.getItem(pos).getCapital(), Toast.LENGTH_LONG).show(); //How to replace this with alertdialog builder
}
});

inputSearch = (EditText) findViewById(R.id.inputSearch);
inputSearch.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
MyActivity2.this.mAdapter.getFilter().filter(cs);
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub

}

@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_activity2, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900