Hi i have this android project where after searching for an Author in the app and the results is clicked i get an empty view instead of the Author displaying his or her quotes
This is the code am using...Thanks
package com.dennisboga.successquotes;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.widget.AdapterView.OnItemClickListener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
public class AuthorsActivity extends Activity {
ListView list;
LazyAuthorsAdapter adapter;
LazyAuthorsAdapter adapterSort;
DAO db;
Cursor cu;
static final String KEY_ID = "_auid";
static final String KEY_NAME = "au_name";
static final String KEY_PICTURE = "au_picture";
static final String KEY_PICTURE_SDCARD = "au_picture_sdcard";
static final String KEY_WEB_ID = "au_web_id";
static final String KEY_COUNT = "count";
static final String KEY_QUOTES_NUM = "quotes_num";
ImageButton search;
EditText inputSearch;
int textlength = 0;
ArrayList<HashMap<String, String>> authorsList;
ArrayList<HashMap<String, String>> authorsListSort = new ArrayList<HashMap<String, String>>();;
HashMap<String, String> map;
// ============================================================================= =
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = new DAO(this);
db.open();
//addAuthors();
//addQuotes();
Cursor c = db.getAllAuthors();
if (c.getCount() != 0) {
setContentView(R.layout.activity_authors);
authorsList = new ArrayList<HashMap<String, String>>();
do {
map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(KEY_ID, c.getString(c.getColumnIndex(KEY_ID)));
map.put(KEY_NAME, c.getString(c.getColumnIndex(KEY_NAME)));
map.put(KEY_PICTURE, c.getString(c.getColumnIndex(KEY_PICTURE)));
map.put(KEY_PICTURE_SDCARD, String.valueOf(c.getInt(c
.getColumnIndex(KEY_PICTURE_SDCARD))));
map.put(KEY_WEB_ID,
String.valueOf(c.getInt(c.getColumnIndex(KEY_WEB_ID))));
map.put(KEY_QUOTES_NUM,
c.getString(c.getColumnIndex(KEY_COUNT)));
// adding HashList to ArrayList
authorsList.add(map);
} while (c.moveToNext());
list = (ListView) findViewById(R.id.list);
// Getting adapter by passing xml data ArrayList
adapter = new LazyAuthorsAdapter(this, authorsList);
list.setAdapter(adapter);
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (authorsListSort.size() != 0) {
map = authorsListSort.get(position);
} else {
map = authorsList.get(position);
}
Intent intent = new Intent(AuthorsActivity.this,
QuotesActivity.class);
intent.putExtra("AuthorId", map.get(KEY_WEB_ID));
intent.putExtra("quotesType", 3);
startActivity(intent);
}
});
search = (ImageButton) findViewById(R.id.search);
inputSearch = (EditText) findViewById(R.id.inputSearch);
search.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (inputSearch.getVisibility() == View.GONE) {
inputSearch.setVisibility(View.VISIBLE);
} else {
inputSearch.setText("");
inputSearch.setVisibility(View.GONE);
}
}
});
inputSearch = (EditText) findViewById(R.id.inputSearch);
inputSearch.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
authorsListSort.clear();
for (int i = 0; i < authorsList.size(); i++) {
map = authorsList.get(i);
String auID = map.get(KEY_ID);
String auName = map.get(KEY_NAME);
String auPicture = map.get(KEY_PICTURE);
String auPictureSDCard = map.get(KEY_PICTURE_SDCARD);
String auQuotesNum = map.get(KEY_QUOTES_NUM);
if (auName.toLowerCase().startsWith(
s.toString().toLowerCase())
|| auName.toLowerCase().contains(
" " + s.toString().toLowerCase())) {
map = new HashMap<String, String>();
// adding each child node to HashMap key =>
// value
map.put(KEY_ID, auID);
map.put(KEY_NAME, auName);
map.put(KEY_PICTURE, auPicture);
map.put(KEY_PICTURE_SDCARD, auPictureSDCard);
map.put(KEY_QUOTES_NUM, auQuotesNum);
// adding HashList to ArrayList
authorsListSort.add(map);
}
}
// }
adapterSort = new LazyAuthorsAdapter(AuthorsActivity.this,
authorsListSort);
list.setAdapter(adapterSort);
}
});
} else {
}
AdView ad = (AdView) findViewById(R.id.adView);
ad.loadAd(new AdRequest.Builder().build());
}
// ============================================================================= =
@Override
protected void onResume() {
db.open();
super.onResume();
}
// ============================================================================= =
@Override
protected void onRestart() {
// TODO Auto-generated method stub
Intent intent = getIntent();
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
startActivity(intent);
super.onRestart();
}
// ============================================================================= =
@Override
protected void onPause() {
db.closeDatabase();
super.onPause();
}
// private void addAuthors() {
// cu = db.getAuthors2();
//
// if (cu.getCount() != 0) {
//
// do {
// db.addAuthors2(cu.getString(cu.getColumnIndex("au_name")),
// cu.getInt(cu.getColumnIndex("_auid")));
//
// } while (cu.moveToNext());
// }
// }
//
// ============================================================================= =
// private void addQuotes() {
// cu = db.getQuotes2();
//
// if (cu.getCount() != 0) {
//
// do {
// db.addQuotes2(cu.getString(cu.getColumnIndex("qu_text")),
// cu.getInt(cu.getColumnIndex("qu_author")),
// cu.getInt(cu.getColumnIndex("_quid")));
//
// } while (cu.moveToNext());
// }
// }
}
Aucun commentaire:
Enregistrer un commentaire