Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!

dinnu goud

Greenhorn
+ Follow
since May 03, 2014
dinnu likes ...
Android Mac OS X Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
14
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by dinnu goud

some how I managed to fix this issue.But it created one more issue.Thanks for your reply steve.My code for onItemClick():

but the problem with this approach is is, I must display an index to user which is bad(after deleting all the items in it, the index begins from where it stopped, instead of starting from the beginning).What i am looking for is when ever an item in the list is clicked,details pertaining to that item should display in the next activity which in my case is displayNames activity.All my application is completed except this.I am webbed here.Please help me get out of this.
6 years ago
hi,I have an arraylist in my android app where I can see list of names like:

1.item
2.item
3.item
4.item
5.item
6.item
7.item ....
1,2,3,4,5,6,7 are coloumn ids in my sqlite database.Column id is set to primary key with auto increment .My problem is when I delete these items and add a new one ,list shows
8.item name(in place of 1.item name) even though there are no elements in it.Which is not appropriate from user's perspective.What I am expecting is ,whenever an item is deleted or all the items are deleted either the column ids should get updated or the newly added item should sit sequentially in the database.

my codes :
for listActivity

DBHelper class:
6 years ago

Why would you "guess"? The stack trace tells you exactly in which line the exception occurs. Which line is it?


Yeah I understand.I followed and got my app problems resolved.Thank you for your responses.

Problems I had at the beginning were:
1.sounds on/off button
2.Updating arraylist items.

Solutions I tried:

In soundsActivity a user can turn on/off sounds by clicking on a button.My code for it is:

I wrote the following code

in onCreate() method to turn on the sounds when app is restarted.


2.Updating arraylist problem.
Initially my arraylist will look like :
1.ItemName1
2.ItemName2
3.ItemName3
4.ItemName4
5.ItemName5 ..........when user clicks on any of the items he will be directed to that particular details activity.This worked fine as far as user doesn't delete any item.When an item is deleted from it ,arraylist should look as: (say ItemName2 is deleted)
1.ItemName1
2.ItemName3
3.ItemName4
4.ItemName5
when ItemName3 is clicked application got crashed.Error was curcor indexOutfBounds:index requested 0 with size 0 exception as I mentioned earlier.I tried to solve it this way:

now my application is working fine.earlier the above block of code I tried was:


The application is working fine so far.I am curious to know whether my approach for sounds on/off button is correct.Because I googled about the problem and what I discovered was
people used the following code to mute/unmute:

I tried this in my app. It muted my app sound but when I restarted the app it got the app sound still muted.I was unable to increase the volume either.so I used setStreamVolume().
Appllication is working fine.Kindly see the above codes and suggest any best practices..Thank you Ulf Sir.
6 years ago
Here lies the problem I guess,

res.moveToFirst();
while(res.isAfterLast() == false)
{
String Index=res.getString(res.getColumnIndex(CONTACTS_COLUMN_ID));
String Name=res.getString(res.getColumnIndex(CONTACTS_COLUMN_NAME));
array_list.add(Index+"."+Name);
res.moveToNext();
}
db.close();
return array_list;
}
6 years ago
sorry sir, i didnt do it deliberately.
It shows nullPointerException,which I will resolve.Sir, now the problem arises in list activity.
ListActivity displays list of items in a list.Like:

1(index autoincrement).Item Name1
2.Item Name2
3.Item Name3
4.Item Name4
5.Item Name5
6.Item Name6.........so on

Problem:If I delete any item say item 2,item 3 goes to item 2 position but the index is not getting updated.Index remains same just positions getting changed.

After deleting item 2.The listActivity displaying like this
1.Item Name1
3.Item Name3
4.Item Name4
5.Item Name5
6.Item Name6......

which I wish it to display as:

1.Item Name1
2.Item Name3
3.Item Name4
4.Item Name5
5.Item Name6......

codes:
DISPLAYCONTACT:

MAINACTIVITY:

DBHELPER:

PROBLEMS:
1.when item 2 is deleted ,item 3 comes to item 2 position but when it is clicked to see the details logcat displays
cursorIndexOutofBoundsException :Index 0 requested, with a size of 0.With my little knowledge I can understand that the error is arising because i am trying to access which is not present.Dear Ulf,Kindly check the code .
6 years ago

Ulf Dittmer wrote:Please don't ever edit a post after there have been responses to it - it makes the responses look either foolish, wrong or meaningless.

I admit my mistake.I wont do that ..Thanks .

6 years ago
it shows nullPointerException,which I will resolve.Sir, now the problem arises in list activity.
ListActivity displays list of items in a list.Like:

1(index autoincrement).Item Name1
2.Item Name2
3.Item Name3
4.Item Name4
5.Item Name5
6.Item Name6.........so on

Problem:If I delete any item say item 2,item 3 goes to item 2 position but the index is not getting updated.Index remains same just positions getting changed.

After deleting item 2.The listActivity displaying like this
1.Item Name1
3.Item Name3
4.Item Name4
5.Item Name5
6.Item Name6......

which is supposed to display as:

1.Item Name1
2.Item Name3
3.Item Name4
4.Item Name5
5.Item Name6......

codes:
DISPLAYCONTACT:
DisplayContact extends activity{

mydb.deleteContact(id_To_Delete);
Toast.makeText(getApplicationContext(), NAME+" 's"+"contact Deleted Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),com.dinesh.contactsBook.MainActivity.class);
startActivity(intent);
}


MAINACTIVITY:
MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
mydb = new DBHelper(this);
ArrayList<String> array_list = mydb.getAllContacts();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, array_list);

obj = (ListView)findViewById(R.id.listView1);
obj.setAdapter(arrayAdapter);
obj.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
int id_To_Search = arg2;
Bundle dataBundle = new Bundle();
dataBundle.putInt("id", id_To_Search);
Intent intent = new Intent(getApplicationContext(),com.dinesh.contactsBook.DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);
}
});
}
catch (Exception e)
{
e.printStackTrace();

}
}

DBHELPER:
public class DBHelper extends SQLiteOpenHelper
{
public Integer deleteContact (Integer id)
{
SQLiteDatabase db = this.getWritableDatabase();
return db.delete("myTable", "id = ? ", new String[] { Integer.toString(id) });

}
public ArrayList<String> getAllContacts()
{
ArrayList<String> array_list = new ArrayList<String>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from myTable", null );
res.moveToFirst();
while(res.isAfterLast() == false)
{
String Index=res.getString(res.getColumnIndex(CONTACTS_COLUMN_ID));
String Name=res.getString(res.getColumnIndex(CONTACTS_COLUMN_NAME));
array_list.add(Index+"."+Name);
res.moveToNext();
}
db.close();
return array_list;
}
}

PROBLEMS:
1.when item 2 is deleted ,item 3 comes to item 2 position but when it is clicked to see the details logcat displays
cursorIndexOutofBoundsException :Index 0 requested, with a size of 0.With my little knowledge I can understand that the error is arising because i am trying to access which is not present.Dear Ulf,Kindly check the code .
6 years ago
Sorry sir, the question was incomplete.I lost internet connectivity before i clicked....here is the complete question
it shows nullPointerException,which I will resolve.Sir, now the problem arises in list activity.
ListActivity displays list of items in a list.Like:

1(index autoincrement).Item Name1
2.Item Name2
3.Item Name3
4.Item Name4
5.Item Name5
6.Item Name6.........so on

Problem:If I delete any item say item 2,
6 years ago
I added this code

if(!mAudioManager.isMusicActive)
{
mAudioManager.setStreamMute(...,false)
}

in my splashActivity onCreate Method But the application is getting crashed.
6 years ago
sir , I solved the problem by doing :

sound_btn=(Button)findViewById(R.id.sounds_on_btn);
mute_btn=(Button)findViewById(R.id.sounds_off_btn);
sound_btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC,false);
Toast.makeText(getApplicationContext(), "Sounds on",Toast.LENGTH_SHORT).show();
}

});

mute_btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC,true);
Toast.makeText(getApplicationContext(), "Sounds Off",Toast.LENGTH_SHORT).show();
}

});

this is working fine sir,but now I am seeing a different problem.This problem is arising if I turn off the sound and close the app.Next time when I start the app it is not giving any sounds.
6 years ago
thanks for your valuable suggestion sir.I Shall practice this from now on..Coming to my logcat :
it displays java.lang.nullpointerException
6 years ago
Dear Ulf sir,

I found it more comfortable to reduce tracking history of activities in activity stack by adding a line of code in manifest file.I solved it by adding a code

<activity android:noHistory="true">in my manifest file.

Sir,is there any possibility of muting/unmuting app sounds from manifest file?
6 years ago
Dear ulf sir,
I am doing that startActivityForResult after it is done I will inform you.

coming to my togglebutton issue,here is the code i wrote so far,

if(myToggleButton.isEnabled()){

audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);


}
else{
audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);


}

the application is crashing whenever I clicked it.
6 years ago
hi,List of Activities in my contacts app goes as:

Splash Activity>Select Activity>here users can select from three options(add contacts,list contacts,settings)
1.add contacts>insert,edit,delete
2.list contacts>list of details will be populated in a list view.
3.settings>Sounds on/off radio or toggle button.
My problems are:
when a user successfully enters details ,a toast is displayed and activity is directed to list where he can see the latest entered contact.This is fine but
1.when he enters back button the user is redirected to the same edit screen which I don't want that to happen.
2.in settings activity I kept a toggle button through which user can set sound on/off.I am unable to implement this .

Any references ,suggestions,code ideas are appreciated.Thanks in Advance
6 years ago
basically I am from java background.thank you rico for your answer.
6 years ago