Show number of Notifications on the side navigation menu - android

I am using Horizontal ScrollView to get facebook like side navigation
Like this:
But how to show that "2" beside the Event item in the menu?
In my application i am using a ViewUtil class to get this menu:
public class ViewUtils {
private ViewUtils() {
}
public static void setViewWidths(View view, View[] views) {
int w = view.getWidth();
int h = view.getHeight();
for (int i = 0; i < views.length; i++) {
View v = views[i];
v.layout((i + 1) * w, 0, (i + 2) * w, h);
printView("view[" + i + "]", v);
}
}
public static void printView(String msg, View v) {
System.out.println(msg + "=" + v);
if (null == v) {
return;
}
System.out.print("[" + v.getLeft());
System.out.print(", " + v.getTop());
System.out.print(", w=" + v.getWidth());
System.out.println(", h=" + v.getHeight() + "]");
System.out.println("mw=" + v.getMeasuredWidth() + ", mh="
+ v.getMeasuredHeight());
System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY()
+ "]");
}
public static void initListView(Context context, ListView listView,
String prefix, int numItems, int layout) {
// By using setAdpater method in listview we an add string array in
// list.
String[] arr = new String[numItems];
arr[0] = "Feed";
arr[1] = "Friends";
arr[2] = "Notifications";
arr[3] = "Feedback";
arr[4] = "Logout";
listView.setAdapter(new ArrayAdapter<String>(context, layout, arr));
}
}
and set the adapter like this in the Activity:
ViewUtils.initListView(this, myListView, "Menu ", 5,
android.R.layout.simple_list_item_1);
I what my "Notifications" Text to be something like "Notification n" where n is like the "2" in the above pic. I tried to use Spannable String but i cannot set the Spannable String to the String Array "arr"
Thank You

I'm assuming those categories (News Feed, Messages,...) are items of a ListView.
Also, for displaying that "2" I'm assuming you will need a custom adapter.
In this case you just need to add a TextView to your row XML file and set the appropriate value in the getView() method of your custom Adapter, or, if you are create the TextView programaticaly in the getView() method.

Related

Display a array of values in a single view in android

Is there any android library to handle this
Above image is a singe view
There should be one view for which I pass array of values like city above
You can try some thing like this , I don't think library is needed
private String getTextToShow(String[] list){
String text="";
if(list==null||list.length==0){
text="No items";
}else if(list.length==1){
text=list[0];
}else if(list.length==2){
text=list[0]+", "+list[1];
}else {
text=list[0]+list[1]+ "+ " +(list.length-2)+" more";
}
return text;
}
you don't need an additional library for this specific task, just concatenate the array elements or list into a single element and display it int the view. An example is given below
public void setView(ArrayList<String> elements){
String result="";
for(String element: elements){
result=result + " " + elements;
}
textview.setText(result);
}
You can use this method which returns a String to bind in the view
private String buildString(ArrayList<String> list, int count) {
StringBuilder ch = new StringBuilder();
if (count <= list.size()) {
for (int i = 0; i < count; i++) {
ch.append(list.get(i)).append(",");
}
return ch.replace(ch.lastIndexOf(","), ch.lastIndexOf(",") + 1, String.format("+ %d more", list.size() - count)).toString();
} else {
for (String s : list) {
ch.append(s).append(",");
}
return ch.substring(0, ch.length() - 1);
}
}

How to implement ListView Pagination from SQLite database in Android?

I want to implement List-View from SQLite Database that i have done. But right now i want to implement pagination on List View setOnScrollListener.First time I'm displaying first 50 records after that when I scroll at the end of list run the progress bar some amount of second and after stop the progress bar another next 50 records append to the list.I'm trying lot of time since 5 days working on List View Pagination but it is not working properly.Can some one help me to resolve this issue.
Here is my code .
listView.addFooterView(footer);
// Implementing scroll refresh
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
#Override
public void onScroll(AbsListView absListView, int firstItem, int visibleItemCount, final int totalItems) {
//Log.e("Get position", "--firstItem:" + firstItem + " visibleItemCount:" + visibleItemCount + " totalItems:" + totalItems + " pageCount:" + pageCount);
int total = firstItem + visibleItemCount;
Log.e("", "onScroll LocalPages=" + LocalPages);
// Total array list i have so it
if (pageCount < LocalPages) {
if (total == totalItems) {
// Execute some code after 8 seconds have passed
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
listView.addFooterView(footer);
OFFSET = pageCount * 50 ;
//Log.e("","After OFFSET pageCount =" + pageCount + " OFFSET value ="+OFFSET);
List<All_Post> allDesc = dbhelper.getAllDescriptions(OFFSET);
for (All_Post all_Post : allDesc)
{
descArray.add(all_Post);
}
if(adapter != null)
{
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
listView.setSelection(totalItems);
pageCount += 1;
Log.e(""," pageCount =" + pageCount + " LocalPages="+LocalPages);
}
}
}, 2000);
}
} else {
Log.e("hide footer", "footer hide");
listView.removeFooterView(footer);
}
}
});
You can do this for following approach.
// create one final list
final ArrayList<String> temp = new ArrayList<String>();
temp.addAll(previous_data);
// call fxn for getting new value
// call your database query
// add new data into list
temp.addAll(new_Data);
// intailize static list of adapter showing data
// add data into list.
ActivityName.MainList = temp;
mAdapter.notifyDataSetChanged();
with your code also... thanks

After rotating screen, always first timer beginning a count

Half month i trying fix this problem, its my second solution and i get old error.
My goal is to write a listView with timer in every row with Start and Stop buttons, after rotating screen all timers should work correctly, but how in pre-solution after rotation screen, first position in listview get time last/lower position.
As for link with these two solution i see just logic of getView() method, and i'm on 100% sure that is the main problem.
Can anybody help me with this, i am at an impasse. Problematic piace of code:
if(isItStart.get(position)){
holder.stop.setEnabled(true);
holder.start.setEnabled(false);
handler.postDelayed(updateTimeThread,0);
}
Here is full class.
ListView listView;
MyAdapter adapter;
Handler handler;
SQLiteDatabase db;
List<Tracker> trackerList;
Tracker tracker;
List<Boolean> isItStart,historyIsItStart;
List<Long> startTime,historyStartTime;
List<Long> lastPauseList,historyLastPauseList;
List<Long> updateTimeList, historyUpdateTimeList;
List<Long> daysList,historyDayList;
List<Long> hoursList,historyHoursList;
List<Long> minutesList,historyMinutes;
List<Long> secondsList,historySecondsList;
int trackerCount;
static final String LOG_TAG = "myTag";
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handler = new Handler();
db = RemindMe.db;
trackerList = Tracker.getListAll(db);
trackerCount=trackerList.size();
initLists();
for (int i = 0; i < trackerCount; i++) {
startTime.add(0L);
lastPauseList.add(0L);
updateTimeList.add(0L);
daysList.add(0L);
hoursList.add(0L);
minutesList.add(0L);
secondsList.add(0L);
isItStart.add(false);
historyStartTime.add(startTime.get(i));
historyLastPauseList.add(lastPauseList.get(i));
historyUpdateTimeList.add(updateTimeList.get(i));
historyDayList.add(daysList.get(i));
historyHoursList.add(hoursList.get(i));
historyMinutes.add(minutesList.get(i));
historySecondsList.add(secondsList.get(i));
historyIsItStart.add(isItStart.get(i));
}
listView = (ListView)findViewById(R.id.listView);
String[] from = {Tracker.COL_NAME,Tracker.COL_ELAPSED_TIME,Tracker.COL_ELAPSED_TIME,Tracker.COL_ELAPSED_TIME,Tracker.COL_ELAPSED_TIME};
int[] to = {R.id.tvName,R.id.tvDays,R.id.tvHours,R.id.tvMinutes,R.id.tvSeconds};
adapter = new MyAdapter(this,R.layout.list_item,Tracker.getAll(db),from,to,0);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
long day,hour,min,sec;
long time = cursor.getLong(columnIndex);
switch(view.getId()){
case R.id.tvDays:
TextView days = (TextView)view;
days.setText("days");
return true;
case R.id.tvHours:
TextView hours = (TextView)view;
hours.setText("hours");
return true;
case R.id.tvMinutes:
TextView minutes = (TextView)view;
minutes.setText("min");
return true;
case R.id.tvSeconds:
TextView seconds = (TextView)view;
if(time!=0){
sec = time/1000;
seconds.setText(String.valueOf(sec));
}else{
seconds.setText("null");
}
return true;
}
return false;
}
});
listView.setAdapter(adapter);
getSupportLoaderManager().initLoader(1,null,this).forceLoad();
}
void initLists(){
startTime = new ArrayList<Long>(trackerCount);
lastPauseList = new ArrayList<Long>(trackerCount);
updateTimeList = new ArrayList<Long>(trackerCount);
daysList = new ArrayList<Long>(trackerCount);
hoursList = new ArrayList<Long>(trackerCount);
minutesList = new ArrayList<Long>(trackerCount);
secondsList = new ArrayList<Long>(trackerCount);
isItStart = new ArrayList<Boolean>(trackerCount);
historySecondsList = new ArrayList<Long>(trackerCount);
historyMinutes = new ArrayList<Long>(trackerCount);
historyHoursList = new ArrayList<Long>(trackerCount);
historyDayList = new ArrayList<Long>(trackerCount);
historyUpdateTimeList = new ArrayList<Long>(trackerCount);
historyLastPauseList = new ArrayList<Long>(trackerCount);
historyStartTime = new ArrayList<Long>(trackerCount);
historyIsItStart = new ArrayList<Boolean>(trackerCount);
}
#Override
public void onClick(View v) {
Intent intent = new Intent(this,AddTrack.class);
startActivity(intent);
}
#Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new TrackerLoader(this,db);
}
#Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
adapter.swapCursor(cursor);
}
#Override
public void onLoaderReset(Loader<Cursor> loader) {
}
static class TrackerLoader extends android.support.v4.content.CursorLoader{
SQLiteDatabase db;
TrackerLoader(Context context,SQLiteDatabase db){
super(context);
this.db=db;
}
#Override
public Cursor loadInBackground() {
return Tracker.getAll(db);
}
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.d(LOG_TAG, "onSavedInstanceState---------------------------------------------------------------!");
for (int i = 0; i <trackerCount ; i++) {
historyStartTime.set(i,startTime.get(i));
historyLastPauseList.set(i, lastPauseList.get(i));
historyUpdateTimeList.set(i,updateTimeList.get(i));
historyDayList.set(i, daysList.get(i));
historyHoursList.set(i,hoursList.get(i));
historyMinutes.set(i, minutesList.get(i));
historySecondsList.set(i,secondsList.get(i));
historyIsItStart.set(i, isItStart.get(i));
outState.putSerializable("startTime " + i, historyStartTime.get(i));
outState.putSerializable("lastPause " + i, historyLastPauseList.get(i));
outState.putSerializable("updateTime " + i, historyUpdateTimeList.get(i));
outState.putSerializable("dayList " + i, historyDayList.get(i));
outState.putSerializable("hoursList " + i, historyHoursList.get(i));
outState.putSerializable("minutesList " + i, historyMinutes.get(i));
outState.putSerializable("secondsList " + i, historySecondsList.get(i));
outState.putSerializable("isItStart " + i, historyIsItStart.get(i));
Log.d(LOG_TAG, "startTime " + getTime((Long) outState.getSerializable("startTime " + i)));
Log.d(LOG_TAG, "lastPause " + getTime((Long) outState.getSerializable("lastPause " + i)));
Log.d(LOG_TAG, "updateTime " + getTime((Long) outState.getSerializable("updateTime " + i)));
Log.d(LOG_TAG, "dayList " + getTime((Long) outState.getSerializable("dayList " + i)));
Log.d(LOG_TAG, "hoursList " + getTime((Long) outState.getSerializable("hoursList " + i)));
Log.d(LOG_TAG, "minutesList " + getTime((Long) outState.getSerializable("minutesList " + i)));
Log.d(LOG_TAG, "secondsList " + outState.getSerializable("secondsList " + i));
Log.d(LOG_TAG, "isItStart " + outState.getSerializable("isItStart " + i));
Log.d(LOG_TAG, "position " + i);
Log.d(LOG_TAG,"-----------------------------------!");
}
Log.d(LOG_TAG,"END onSavedInstanceState-------------------------------------------------------------!");
for (int i = 0; i < trackerCount; i++) {
Log.d(LOG_TAG,"secondsList "+i+ " "+secondsList.get(i));
}
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.d(LOG_TAG, "onRestoreInstanceState-------------------------------------------------------!");
for (int i = 0; i <trackerCount ; i++) {
historyStartTime.set(i,(Long)savedInstanceState.getSerializable("startTime "+i));
historyLastPauseList.set(i,(Long)savedInstanceState.getSerializable("lastPause "+i));
historyUpdateTimeList.set(i,(Long)savedInstanceState.getSerializable("updateTime "+i));
historyDayList.set(i,(Long)savedInstanceState.getSerializable("dayList "+i));
historyHoursList.set(i,(Long)savedInstanceState.getSerializable("hoursList "+i));
historyMinutes.set(i,(Long)savedInstanceState.getSerializable("minutesList "+i));
historySecondsList.set(i,(Long)savedInstanceState.getSerializable("secondsList "+i));
historyIsItStart.set(i,(Boolean)savedInstanceState.getSerializable("isItStart "+i));
startTime.set(i,historyStartTime.get(i));
lastPauseList.set(i,historyLastPauseList.get(i));
updateTimeList.set(i,historyUpdateTimeList.get(i));
daysList.set(i,historyDayList.get(i));
hoursList.set(i,historyHoursList.get(i));
minutesList.set(i,historyMinutes.get(i));
secondsList.set(i,historySecondsList.get(i));
isItStart.set(i, historyIsItStart.get(i));
Log.d(LOG_TAG, "startTime " + getTime((Long) savedInstanceState.getSerializable("startTime " + i)));
Log.d(LOG_TAG,"lastPause " + getTime((Long) savedInstanceState.getSerializable("lastPause " + i)));
Log.d(LOG_TAG,"updateTime " + getTime((Long) savedInstanceState.getSerializable("updateTime " + i)));
Log.d(LOG_TAG,"dayList " + getTime((Long) savedInstanceState.getSerializable("dayList " + i)));
Log.d(LOG_TAG,"hoursList " + getTime((Long) savedInstanceState.getSerializable("hoursList " + i)));
Log.d(LOG_TAG,"minutesList " + getTime((Long) savedInstanceState.getSerializable("minutesList " + i)));
Log.d(LOG_TAG, "secondsList " + savedInstanceState.getSerializable("secondsList " + i));
Log.d(LOG_TAG,"isItStart "+savedInstanceState.getSerializable("isItStart " + i));
Log.d(LOG_TAG,"position "+i);
Log.d(LOG_TAG,"----------------------------------------------------------------");
}
Log.d(LOG_TAG,"END onRestoreIntstanceState-------------------------------------------------------------!");
}
private class MyAdapter extends SimpleCursorAdapter{
Context context;
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
MyAdapter(Context context,int resourceID,Cursor cursor,String[] from,int[]to,int flags){
super(context, resourceID, cursor, from, to, flags);
this.context = context;
}
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View row = convertView;
final ViewHolder holder;
tracker = trackerList.get(position);
if(row==null){
holder = new ViewHolder();
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(R.layout.list_item,parent,false);
holder.name= (TextView)row.findViewById(R.id.tvName);
holder.days = (TextView)row.findViewById(R.id.tvDays);
holder.hours = (TextView)row.findViewById(R.id.tvHours);
holder.minutes = (TextView)row.findViewById(R.id.tvMinutes);
holder.seconds = (TextView)row.findViewById(R.id.tvSeconds);
holder.start = (Button)row.findViewById(R.id.btStart);
holder.stop = (Button)row.findViewById(R.id.btStop);
row.setTag(holder);
}else{
holder = (ViewHolder)row.getTag();
}
holder.start.setEnabled(true);
holder.stop.setEnabled(false);
holder.name.setText(tracker.getName());
final Runnable updateTimeThread = new Runnable() {
#Override
public void run() {
updateTimeList.set(position, (System.currentTimeMillis() - startTime.get(position)) + lastPauseList.get(position));
secondsList.set(position, updateTimeList.get(position) / 1000);
minutesList.set(position, secondsList.get(position) / 60);
hoursList.set(position, minutesList.get(position) / 60);
secondsList.set(position, (secondsList.get(position) % 60));
minutesList.set(position, (minutesList.get(position) % 60));
hoursList.set(position, (hoursList.get(position) % 24));
holder.days.setText(String.format("%04d", daysList.get(position)));
holder.hours.setText(String.format("%02d", hoursList.get(position)));
holder.minutes.setText(String.format("%02d", minutesList.get(position)));
holder.seconds.setText(String.format("%02d", secondsList.get(position)));
handler.postDelayed(this, 0);
}
};
if(isItStart.get(position)){
holder.stop.setEnabled(true);
holder.start.setEnabled(false);
handler.postDelayed(updateTimeThread,0);
}
View.OnClickListener onClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btStart:
startTime.set(position,System.currentTimeMillis());
handler.post(updateTimeThread);
holder.start.setEnabled(false);
holder.stop.setEnabled(true);
isItStart.set(position,true);
break;
case R.id.btStop:
lastPauseList.set(position, updateTimeList.get(position));
handler.removeCallbacks(updateTimeThread);
holder.stop.setEnabled(false);
holder.start.setEnabled(true);
isItStart.set(position,false);
break;
}
}
};
holder.start.setOnClickListener(onClickListener);
holder.stop.setOnClickListener(onClickListener);
return row;
}
class ViewHolder{
TextView name,days,hours,minutes,seconds;
Button start,stop;
}
}
String getTime(long time){
int hours = (int)(time/3600000);
int minutes = (int)(time -hours*3600000)/60000;
int seconds = (int)(time-hours*3600000-minutes*60000)/1000;
String hour = (hours<9?"0"+hours:hours).toString();
String min = (minutes<9?"0"+minutes:minutes).toString();
String sec = (seconds<9?"0"+seconds:seconds).toString();
return ""+hour+":"+min+":"+sec;
}
}
Add android:configChanges="orientation|screenSize" in manifest.xml and delete your onRestore and onSaved.
When you rotating the screen the application refresh the activity i had the same kind of problem so i just locked the screen for one way in the android mainifest by
android:screenOrientation="portrait"
found this great answer by:Xion
"you could distinguish the cases of your activity being created for the first time and being restored from savedInstanceState. This is done by overriding onSaveInstanceState and checking the parameter of onCreate.
You could lock the activity in one orientation by adding android:screenOrientation="portrait" (or "landscape") to in your manifest.
You could tell the system that you meant to handle screen changes for yourself by specifying android:configChanges="orientation" in the tag. This way the activity will not be recreated, but will receive a callback instead (which you can ignore as it's not useful for you)."

No items on ListControl

I have a problem while displaying a list on Sony SmartWatch 2.
I copied layouts from sample project (AdvancedControlSample) and I have the following class:
public class OpenPositionsView extends ControlExtension implements BaseView {
private static final String LOG_TAG = "TAGG";
private Context context;
private ControlViewGroup mLayout;
public OpenPositionsView(Context context, String hostAppPackageName) {
super(context, hostAppPackageName);
this.context = context;
mLayout = setup();
}
public ControlViewGroup setup() {
Log.i(LOG_TAG, "setup");
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.watch_positions, null);
ControlViewGroup mLayout = (ControlViewGroup) parseLayout(layout);
return mLayout;
}
public void show(Controller parent) {
int listCount = DataProvider.getInstance().getPositions().size();
parent.sendListCountM(R.id.watch_positions_listview, listCount);
parent.sendListPositionM(R.id.watch_positions_listview, 0);
parent.refreshLayout(R.layout.watch_positions, null);
Log.i(LOG_TAG, "show [listCount: " + listCount + "]");
}
#Override
public void onRequestListItem(final int layoutReference, final int listItemPosition) {
Log.d(LOG_TAG, "onRequestListItem [layoutReference: " + layoutReference + ", position: " + listItemPosition + "]");
if (layoutReference != -1 && listItemPosition != -1 && layoutReference == R.id.watch_positions_listview) {
ControlListItem item = createControlListItem(listItemPosition);
if (item != null) {
Log.d(LOG_TAG, "Sending list item");
sendListItem(item);
}
}
}
#Override
public void onListItemSelected(ControlListItem listItem) {
super.onListItemSelected(listItem);
}
#Override
public void onListItemClick(final ControlListItem listItem, final int clickType, final int itemLayoutReference) {
Log.d(LOG_TAG, "onListItemClick [listItemPosition: " + listItem.listItemPosition + ", clickType: " + clickType + ", itemLayoutReference: "
+ itemLayoutReference + "]");
}
public void onClick(int id) {
mLayout.onClick(id);
}
protected ControlListItem createControlListItem(int position) {
Log.d(LOG_TAG, "createControlListItem [position: " + position + "]");
ControlListItem item = new ControlListItem();
item.layoutReference = R.id.watch_positions_listview;
item.dataXmlLayout = R.layout.watch_positions_item;
item.listItemPosition = position;
// We use position as listItemId. Here we could use some other unique id
// to reference the list data
item.listItemId = position;
Position target = DataProvider.getInstance().getPosition(position);
if (target != null) {
Bundle symbolBundle = new Bundle();
symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol);
symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol());
Bundle typeBundle = new Bundle();
typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type);
typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString());
item.layoutData = new Bundle[2];
item.layoutData[0] = symbolBundle;
item.layoutData[1] = typeBundle;
Log.d(LOG_TAG, "Item list created: [symbolBundle: " + symbolBundle + ", typeBundle: " + typeBundle + "]");
}
return item;
}
protected Bundle[] createBundle(int position) {
Bundle[] result = new Bundle[2];
Position target = DataProvider.getInstance().getPosition(position);
if (target != null) {
Bundle symbolBundle = new Bundle();
symbolBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_symbol);
symbolBundle.putString(Control.Intents.EXTRA_TEXT, target.getSymbol());
Bundle typeBundle = new Bundle();
typeBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.watch_position_type);
typeBundle.putString(Control.Intents.EXTRA_TEXT, target.getTypeAsString());
result[0] = symbolBundle;
result[1] = typeBundle;
}
return result;
}
}
However, onRequestListItem gets called and createControlListItem returns a correct item list. Touching the display gives me the following result:
onListItemClick [listItem: com.sonyericsson.extras.liveware.extension.util.control.ControlListItem#423b6960, clickType: 0, itemLayoutReference: -1]
The problem is, I do not see any of "added" list items :(
Make sure you also copied the List-related intents from the Manifest.xml:
<action android:name="com.sonyericsson.extras.aef.control.LIST_REFERESH_REQUEST" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_REQUEST_ITEM" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_CLICK" />
<action android:name="com.sonyericsson.extras.aef.control.LIST_ITEM_SELECTED" />
Couple questions for you:
What is being shown on the screen? Is it just blank?
Are you calling showLayout() and sendListCount()? I don't see them in the above code. In the sample code in onResume() you should see something like:
showLayout(R.layout.layout_test_list, null);
sendListCount(R.id.listView, mListContent.length);
These need to be called.
Did you make sure that sendListItem(item) is actually being called?
Aren't you adding black text items to layout with black background? :) Please check your layouts.

TextViews become uneditable after reactivating activity?

So currently I am making an educational application where users can view how to solve a given problem by pressing a button. While my code works fine initially, when I hit the back button and click my View Solution button, my default layout pops up and I cannot edit the last four TextViews. Here is my code:
public class AdditionTensSolutionActivity extends Activity {
public static ArrayList<TextView> explain = new ArrayList<TextView>(3);
public static Button nextstep;
public static int onesnum1 = TensAdditionExerciseActivity.n1display % 10;
public static int onesnum2 = TensAdditionExerciseActivity.n2display % 10;
public static int onesanswer = onesnum1 + onesnum2;
public static int onesanswermod = onesanswer % 10;
public static int tensnum1 = TensAdditionExerciseActivity.n1display / 10;
public static int tensnum2 = TensAdditionExerciseActivity.n2display / 10;
public static int tensanswer = tensnum1 + tensnum2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showsolutionlayout);
TextView numrow1 = (TextView) findViewById(R.id.solproblemrow1);
TextView numrow2 = (TextView) findViewById(R.id.solproblemrow2);
TextView solution = (TextView) findViewById(R.id.solutiontextview);
TextView carryover = (TextView) findViewById(R.id.carryovernumbers);
TextView exp1 = (TextView) findViewById(R.id.explain1);
TextView exp2 = (TextView) findViewById(R.id.explain2);
TextView exp3 = (TextView) findViewById(R.id.explain3);
TextView exp4 = (TextView) findViewById(R.id.explain4);
numrow1.setText(TensAdditionExerciseActivity.n1display + "");
numrow2.setText(" " + TensAdditionExerciseActivity.n2display + " +");
explain.add(exp1);
explain.add(exp2);
explain.add(exp3);
explain.add(exp4);
nextstep = (Button) findViewById(R.id.nextstep);
for (int i = 0; i < 4; i++) {
explain.get(i).setVisibility(View.GONE);
}
solution.setVisibility(View.GONE);
carryover.setVisibility(View.GONE);
explain.get(0).setText("test");
setTextViews();
nextButtonsetOnClickListener();
}
protected void nextButtonsetOnClickListener() {
nextstep.setOnClickListener(new View.OnClickListener() {
int i = 0;
public void onClick(View v) {
explain.get(i).setVisibility(View.VISIBLE);
i++;
if (i > 2 && onesanswer < 10) {
nextstep.setClickable(false);
}
if (i > 3 && onesanswer >= 10) {
nextstep.setClickable(false);
}
}
});
}
protected void setTextViews() {
explain.get(0).setText(
"Add " + (onesnum1) + " and " + (onesnum2) + " which equals "
+ (onesanswer) + ".");
if (onesanswer >= 10) {
explain.get(1).setText(
"Since the answer is 10 or greater, 1 must carry over to the tens place and "
+ onesanswermod + " is left in the ones place.");
explain.get(2).setText(
"Add the tens place digits, " + tensnum1 + " and "
+ tensnum2
+ ". Don't forget to add the carried over 1!");
explain.get(3).setText(
"1 + " + tensnum1 + " + " + tensnum2 + " = "
+ (tensanswer + 1));
} else {
explain.get(1).setText(
"Add the tens place digits: " + tensnum1 + " and "
+ tensnum2 + ".");
explain.get(2).setText(
tensnum1 + " + " + tensnum2 + " = " + tensanswer);
}
Ah, I figured it out. I had my ArrayList set to static rather than final, but I still do not completely the entirety of my error. Would someone be willing to tell me why it made such a big difference?
A static variable / method has only one instance for the entire class. That means, that in the case of your listview, only one exists for all instances of your activity in the entire app, which is why your getting your error. Final means that it can't be initialized anywhere other than the constructor or when the variable is defined. (Difference between Static and final?).

Categories

Resources