Side menu turns white when I scroll dow - java

I am trying to implement a side menu in my application it works fine for the most part, but the problem I have is that once I display de menu and try to scroll down the whole list turns white (background) and the text disappears.
http://i.imgur.com/6a6TgJJ.png
http://i.imgur.com/ykT7hCN.png
Above I attach two pictures showing the behavior of the menu, when I slide my finger from the left to the right the side menu shows, but if I scroll down in the menu, it becomes an empty white list, here is my code:
public class ControlApp extends SlidingActivity{
ArrayList<String> datos ;
ArrayAdapter<String> adaptador;
Intent intent;
private String[] mMenuLista;
// private MyCustomAdapter mAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notificaciones);
setBehindContentView(R.layout.activity_menu);
Parse.initialize(this, "BqCCNsbb14MPgeWz3rznxO4DamuXUbsgiTug8P8I", "9j7GSLWnV46fkPsNMwnMD2FormAiclKlGitfDq2b");
ParseAnalytics.trackAppOpened(getIntent());
getSlidingMenu().setBehindOffset(100);
// mAdapter = new MyCustomAdapter();
PushService.setDefaultPushCallback(this, Notificaciones.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
mMenuLista = getResources().getStringArray(R.array.lista_menu);
// for(int i=0; i<=9;i++){
// mAdapter.addItem(mMenuLista[i]);
// if(i == 9){
// mAdapter.addSeparatorItem(mMenuLista[i]);
// }
// }
ListView primario = (ListView) findViewById(R.id.left_drawer);
primario.setAdapter(new ArrayAdapter<String>(this,R.layout.drawer_list, mMenuLista));
primario.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> pariente, View view, int posicion, long id) {
selectItem(posicion);
}
});
}
public void selectItem(int posicion){
switch (posicion) {
case 0:
intent = new Intent(ControlApp.this, Notificaciones.class);
startActivity(intent);
break;
case 1:
intent = new Intent(ControlApp.this, Calificaiones.class);
startActivity(intent);
break;
case 2:
intent = new Intent(ControlApp.this, Mensajes.class);
startActivity(intent);
break;
case 3:
intent = new Intent(ControlApp.this, Citas.class);
startActivity(intent);
break;
case 4:
intent = new Intent(ControlApp.this, Permisos.class);
startActivity(intent);
break;
case 5:
intent = new Intent(ControlApp.this, Eventos.class);
startActivity(intent);
break;
case 6:
intent = new Intent(ControlApp.this, Horarios.class);
startActivity(intent);
break;
case 7:
intent = new Intent(ControlApp.this, Circulares.class);
startActivity(intent);
break;
case 8:
intent = new Intent(ControlApp.this, ProgramaDeEstudios.class);
startActivity(intent);
break;
case 9:
intent = new Intent(ControlApp.this, Ajustes.class);
startActivity(intent);
break;
case 10:
ParseUser.logOut();
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser == null){
// sesion cerrada correctamente
Toast toast = Toast.makeText(getApplicationContext(), "SesiĆ³n cerrada correctamente", Toast.LENGTH_SHORT);
toast.show();
Intent regis = new Intent (ControlApp.this, MainActivity.class);
startActivity(regis);
finish();
}else{
Toast toast = Toast.makeText(getApplicationContext(), "No se logro cerrar sesion, intentelo de nuevo", Toast.LENGTH_SHORT);
toast.show();
}
break;
default:
break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I hope someone can help me find my mistakes so I can correct the error. thank you!!!

I'm guessing you are manually setting the background color of a ListView in your menu to black, while the main activity theme has a white background?
You need to set the android:cacheColorHint attribute on the ListView to match the list background color. The white is appearing due to rendering optimization by Android which uses that cacheColorHint value to quickly redraw the list while scrolling.
I read a good blog post detailing this issue once. I can't find it right now but will link to it if I do :)

Related

Cannot resolve symbol 'item'

I'm trying to make my menu items go to different activities, so I tried to override the onOptionsItemSelcted on every activity, but I'm getting this error.
also getting "Constant expression required" on every case "R.id.ItemX".
#Override
public boolean onOptionsItemSelected(MenuItem menu){
switch (item.getItemId()){ // ERROR IS HERE ON THE WORD 'item', Cannot resolve symbol 'item'.
Intent goToNextActivity = new Intent(getApplicationContext(), MainActivity.class);
case R.id.Item1: // Constant expression required
goToNextActivity = new Intent(getApplicationContext(), MainActivity.class);
startActivity(goToNextActivity);
break;
case R.id.Item2: // Constant expression required
goToNextActivity = new Intent(getApplicationContext(), VidPage.class);
startActivity(goToNextActivity);
break;
case R.id.Item3: // Constant expression required
goToNextActivity = new Intent(getApplicationContext(), DatePage.class);
startActivity(goToNextActivity);
break;
}
return true;
}
Use this
menu.getItemId()
Instead of this
item.getItemId()
SAMPLE CODE
#Override
public boolean onOptionsItemSelected(MenuItem menu){
switch (menu.getItemId()){ // ERROR IS HERE ON THE WORD 'item', THE REST WORKS FINE.
Intent goToNextActivity = new Intent(getApplicationContext(), MainActivity.class);
case R.id.Item1:
goToNextActivity = new Intent(getApplicationContext(), MainActivity.class);
startActivity(goToNextActivity);
break;
case R.id.Item2:
goToNextActivity = new Intent(getApplicationContext(), VidPage.class);
startActivity(goToNextActivity);
break;
case R.id.Item3:
goToNextActivity = new Intent(getApplicationContext(), DatePage.class);
startActivity(goToNextActivity);
break;
}
return true;
}
use this
menu.getItemId()
this will return you the item id,

Android Studio Beginner;

So here's my code:
public class MainActivity extends AppCompatActivity {
/* access modifiers changed from: protected */
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
}
public void onClick(View view) {
Intent intent;
switch (view.getId()) {
case R.id.button: // Text
intent = new Intent(this,"Faiz Ahmed \nLove music forever\nTCSS 450");
break;
case R.id.button2: // Image
intent = new Intent(this, ImageActivity.class);
break;
case R.id.button3: // Web
intent = new Intent("android.intent.action.VIEW");
intent.setData(Uri.parse("http://developer.android.com"));
break;
case R.id.button4: // Toast
Toast.makeText(this, "Here's to a new quarter!", Toast.LENGTH_SHORT)
.show();
break;
case R.id.button5: // Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("I am a dialog").setTitle("Some Title").create().show();
}
intent = null;
if (intent != null) {
startActivity(intent);
}
}
}
All the import's are there I just for some reason none of the buttons are working. The first 2 (Text & Image) I know I need a lot more code, but the last 3 should work & they're not for some reason. Any know what I'm doing wrong & how to fix it?
Nothing of the buttons will work because in the switch-case statement you initialize the intent according to which button was pressed.
After that you set intent to null and lastly you start the activity if the intent is not null, but it always is (since you set it before to null).
Short story delete intent = null; statement.
// intent = null; delete this line
if (intent != null) {
startActivity(intent);
}

New Activity from ListView

I'm working on a music sheet app, and have a bunch of songs in a ListView.
I'm using an onItemClick method, but the problem is, I don't know how to open an activity depending on what subitem is selected.
The array of songs is uta[], so I can find the specific String with uta[position], but how can I open a specific activity based off of the position that is picked by the user in the ListView?
You can make a switch/case statement on the String that you fetch with uta[position]
public void onItemClick(AdapterView parent, View v, int position, long id) {
String value = uta[position].getValue();
switch(value){
case "value1":
Intent intent = new Intent(this, activity1.class); startActivity(intent);
break;
case "value2":
Intent intent = new Intent(this, activity2.class); startActivity(intent);
break;
case "value3":
Intent intent = new Intent(this, activity3.class); startActivity(intent);
break;
}
}
Note: switch/case statement on Strings requires JDK 7, see the Oracle documentation.
Try in this manner in your onitemclick method
if (position == 0) {
Intent intent = new Intent(this, activity1.class);
startActivity(intent);
} else if (position == 1) {
Intent intent = new Intent(this, activity2.class);
startActivity(intent);
} else if (position == 2){
Intent intent = new Intent(this, activity3.class);
startActivity(intent);
}
Your ListView item-click listener provides the view that has been clicked:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Song song = (Song) getItemAtPosition(position);
if (song.getId() == SOME_ID)
startActivity(new Intent(this, SomeActivity.class));
// you can then create the logic for all your activities
}
});
Also, you may pass the song to one activity that would load itself based on the song data. For that, I recommend you read about the Parcelable interface and how to put Extras in an Intent.
Can you use:
listView1.setOnItemClickListener(new AdapterView.onItemClickListener() {
#Override
public void onItemClick(AdapterView adapter, View view, int position, long arg) {
switch (position) {
case 0:
startActivity(new Intent(this, first_activity.class));
break;
case 1:
startActivity(new Intent(this, second_activity.class));
break;
// and more...
}
});
Cheers!

ExpandableListView OnClick go to the activity does not work

I have got ExpandableListView. It looks like this http://www.androidhive.info/wp-content/uploads/2013/07/android-expandable-listview.jpg . I just want to OnChildClick for example Despicable Me 2 go to the SecondActivity and send PutExtra string with "Despicable Me 2". I know how to use PutExtra and GetExtra method.
Can someone give me advice how to solve this problem? I tried to go with switches but it does not work it does not do anything(It just stay in ExpandableListView).
Here is MainActivity.java:
Public string movie;
expListView.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Intent intent0 = new Intent(getApplicationContext(), SecondActivity.class);
switch(groupPosition)
{
//Top250
case 0: switch(childPosition)
{
case 0: movie="The Conjuring";
intent0.putExtra("text1", movie);
startActivity(intent0);
break;
case 1: movie="Despicable Me 2";
intent0.putExtra("text1", movie);
startActivity(intent0);
break;
}
break;
//Now Showing
case 1: switch(childPosition)
{
case 0:
break;
}
break;
//Coming Soon
case 2:switch(childPosition)
{
case 0:
break;
}
break;
}
return false;
}
});
I downloaded this code from http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/ you can see all of xml and activities here except SecondActivity.
try to put the intent inside the switch case
like this
case 0: switch(childPosition)
{
case 0: Intent intent0 = new Intent(getApplicationContext(), SecondActivity.class);
movie="The Conjuring";
intent0.putExtra("text1", movie);
startActivity(intent0);
break;
or
if(childPosition ==1)
Intent intent0 = new Intent(getApplicationContext(), SecondActivity.class);
movie="The Conjuring";
intent0.putExtra("text1", movie);
startActivity(intent0);

How does radio button stay selected when other activity is initiated using an intent?

My Main activity has a group radio buttons. When each of them is clicked, it initiates a different activity. All the activities have the same XML but the inputs and the functionality is different. What I mean is the radio group is common for all Activities. For Example: When a first radio button is clicked, it initiates a different activity and the radio box selection disappears. I need the clicked radio button selection to stay on until a different radio button from the group is clicked though it is in a different activity. How do I get this working? Any help will be greatly appreciated!
public void onRadioButtonClicked(View view){
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radio_199os:
if (checked){
Intent intent = new Intent(MainActivity.this, second.class);
startActivity(intent);
}
break;
case R.id.radio_399os:
if (checked){
Intent intent = new Intent(MainActivity.this, Third.class);
startActivity(intent);
}
break;
case R.id.radio_2000os:
if (checked){
Intent intent = new Intent(MainActivity.this, Fourth.class);
startActivity(intent);
}
//
break;
}
}
you need to add the following to make checked
check for selected
radio_2000os.setChecked(true);
uncheck for others
radio_199os.setChecked(false);
your Code would be like this
public void onRadioButtonClicked(View view){
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radio_199os:
if (checked){
Intent intent = new Intent(MainActivity.this, second.class);
startActivity(intent);
radio_2000os.setChecked(false);
radio_399os.setChecked(false);
radio_199os.setChecked(true);
}
break;
case R.id.radio_399os:
if (checked){
Intent intent = new Intent(MainActivity.this, Third.class);
startActivity(intent);
radio_2000os.setChecked(false);
radio_399os.setChecked(true);
radio_199os.setChecked(false);
}
break;
case R.id.radio_2000os:
if (checked){
Intent intent = new Intent(MainActivity.this, Fourth.class);
startActivity(intent);
radio_2000os.setChecked(true);
radio_399os.setChecked(false);
radio_199os.setChecked(false);
}
//
break;
}
}

Categories

Resources