1. Download our Official Android App: Forums for Android!

Apps startActivity starts blank XML?

Discussion in 'Android Development' started by kodieh, May 9, 2016.

  1. kodieh

    kodieh Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    4
    Joined:
    May 9, 2016

    May 9, 2016
    4
    0
    15
    Male
    listview.xml
    Code (Text):
    1.  
    2.     <!--?xml version="1.0" encoding="utf-8"?-->
    3.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.         android:orientation="vertical"
    5.         android:layout_width="fill_parent"
    6.         android:layout_height="wrap_content">
    7.         <ListView
    8.             android:layout_width="fill_parent"
    9.             android:layout_height="wrap_content"
    10.             android:focusable="false"
    11.             android:id="@+id/lstText">
    12.         </ListView>
    13.     </LinearLayout>
    14.  
    ListView Code
    Code (Text):
    1.  
    2.     package saint.animaltracking;
    3.    
    4.     import android.content.Intent;
    5.     import android.os.Bundle;
    6.     import android.support.v7.app.AppCompatActivity;
    7.     import android.view.View;
    8.     import android.widget.AdapterView;
    9.     import android.widget.ListView;
    10.    
    11.     import java.util.List;
    12.    
    13.     import saint.animaltracking.helper.AnimalAdapter;
    14.     import saint.animaltracking.helper.DatabaseHelper;
    15.    
    16.     /**
    17.      * Created by Kodie on 3/28/2016.
    18.      */
    19.     public class selectAnimal extends AppCompatActivity
    20.     {
    21.         private ListView lv;
    22.         private List<animal> animal;
    23.         private DatabaseHelper db;
    24.         AnimalAdapter adapter;
    25.         @Override
    26.         protected void onCreate(final Bundle savedInstanceState)
    27.         {
    28.             super.onCreate(savedInstanceState);
    29.             db = new DatabaseHelper(this.getApplicationContext());
    30.             setContentView(R.layout.main);
    31.             animal = db.getAllAnimal();
    32.             lv = (ListView) findViewById(R.id.lstText);
    33.    
    34.             adapter = new AnimalAdapter(this, R.layout.list_item, animal);
    35.    
    36.             lv.setAdapter(adapter);
    37.             lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    38.                 @Override
    39.                 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    40.                     animal anim = (animal) lv.getItemAtPosition(position);
    41.                     Intent intent = new Intent(getApplicationContext(), specific.class);
    42.                     intent.putExtra("animal", anim);
    43.                     startActivity(intent);
    44.                 }
    45.             });
    46.         }
    47.     }
    48.  
    specific.class xml (Generic as I am trying to debug the issue)
    Code (Text):
    1.  
    2.     <?xml version="1.0" encoding="utf-8"?>
    3.     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.         android:layout_width="fill_parent"
    5.         android:layout_height="fill_parent" >
    6.    
    7.         <Button
    8.             android:id="@+id/btnButton1"
    9.             android:layout_width="wrap_content"
    10.             android:layout_height="wrap_content"
    11.             android:text="Button 1"/>
    12.    
    13.         <Button
    14.             android:id="@+id/btnButton2"
    15.             android:layout_width="wrap_content"
    16.             android:layout_height="wrap_content"
    17.             android:text="Button 2"
    18.             android:layout_toRightOf="@+id/btnButton1"/>
    19.    
    20.         <Button
    21.             android:id="@+id/btnButton3"
    22.             android:layout_width="wrap_content"
    23.             android:layout_height="wrap_content"
    24.             android:text="Button 3"
    25.             android:layout_below="@+id/btnButton1"/>
    26.    
    27.         <TextView
    28.             android:id="@+id/textView1"
    29.             android:layout_width="wrap_content"
    30.             android:layout_height="wrap_content"
    31.             android:layout_below="@+id/btnButton3"
    32.             android:layout_marginTop="94dp"
    33.             android:text="User :"
    34.             android:textAppearance="?android:attr/textAppearanceLarge" />
    35.    
    36.         <EditText
    37.             android:id="@+id/editText1"
    38.             android:layout_width="wrap_content"
    39.             android:layout_height="wrap_content"
    40.             android:layout_alignParentRight="true"
    41.             android:layout_alignTop="@+id/textView1"
    42.             android:layout_toRightOf="@+id/btnButton3" />
    43.    
    44.         <Button
    45.             android:id="@+id/btnSubmit"
    46.             android:layout_width="wrap_content"
    47.             android:layout_height="wrap_content"
    48.             android:layout_alignParentRight="true"
    49.             android:layout_below="@+id/editText1"
    50.             android:text="Submit" />
    51.    
    52.     </RelativeLayout>
    53.  
    Specific.java code
    Code (Text):
    1.  
    2.     package saint.animaltracking;
    3.    
    4.     import android.content.Intent;
    5.     import android.database.sqlite.SQLiteOpenHelper;
    6.     import android.os.Bundle;
    7.     import android.support.v7.app.AppCompatActivity;
    8.     import android.view.View;
    9.     import android.widget.TextView;
    10.    
    11.     /**
    12.      * Created by Kodie on 5/2/2016.
    13.      */
    14.     public class specific extends AppCompatActivity {
    15.         String id;
    16.         private SQLiteOpenHelper AT;
    17.    
    18.         public void onCreate(Bundle savedInstanceState) {
    19.            
    20.             super.onCreate(savedInstanceState);
    21.             setContentView(R.layout.specific);
    22.             Intent intent = getIntent();
    23.         }
    24.     }
    25.  
    The issue I am running into is that when I click the specific listview item to go to the specific animal, all it shows is a blank page. I'm not really sure why though, but I have a strong feeling it has something to do with the way I am writing the OnItemClickListener and OnItemClick or how it is passing the intent to the specific.java class? I've done just about everything I can think of (I've been working in android for about three weeks) to resolve this, outside of trying to rewrite the OnItemClickListener section. Any tips in the right direction are greatly appreciated. Thanks in advance.

    UPDATE:
    I get the following messages repeatedly when clicking the listitem

    > W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent...

    > E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb40d53a0
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,292
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,292
    10,403
    1,988
    Male
    Software developer
    South West of England
    If you set a breakpoint at line 21 in specific.java, does it get hit?
     
    kodieh likes this.
  3. kodieh

    kodieh Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    4
    Joined:
    May 9, 2016

    May 9, 2016
    4
    0
    15
    Male
    Yes, and the savedInstanceState is null at that breakpoint.
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,292
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,292
    10,403
    1,988
    Male
    Software developer
    South West of England
    That's puzzling, you seem to be doing everything right.
    I'll have a further think about it..
     
  5. kodieh

    kodieh Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    4
    Joined:
    May 9, 2016

    May 9, 2016
    4
    0
    15
    Male
    Thanks! I'm puzzled as well.
     
  6. kodieh

    kodieh Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    4
    Joined:
    May 9, 2016

    May 9, 2016
    4
    0
    15
    Male
    If I point the setContentView to add.xml it will display this xml.

    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <ScrollView
    4.     xmlns:android="http://schemas.android.com/apk/res/android"
    5.     android:id="@+id/AddAnimal"
    6.     android:layout_width="wrap_content"
    7.     android:layout_height="wrap_content"
    8.     android:scrollbars="vertical">
    9.     <LinearLayout
    10.         android:layout_width="fill_parent"
    11.         android:orientation="vertical"
    12.         android:layout_height="fill_parent">
    13.     <!--Form controls to follow-->
    14.         <TextView
    15.             android:id="@+id/TextViewTitle"
    16.             android:layout_width="fill_parent"
    17.             android:layout_height="wrap_content"
    18.             android:text="@string/formTitle"
    19.             android:textSize = "10pt">
    20.             </TextView>
    21.         <EditText
    22.             android:id="@+id/EditTextMorph"
    23.             android:layout_height="wrap_content"
    24.             android:hint="@string/morph"
    25.             android:inputType="textPersonName"
    26.             android:layout_width="fill_parent">
    27.         </EditText>
    28.         <Spinner
    29.             android:id="@+id/SpinnerSex"
    30.             android:layout_height="wrap_content"
    31.             android:prompt="@string/sex"
    32.             android:layout_width="fill_parent"
    33.             android:entries="@array/genderlist">
    34.         </Spinner>
    35.  
    36.         <Button
    37.             android:id="@+id/ButtonSendFeedback"
    38.             android:layout_height="169dp"
    39.             android:text="@string/feedbackbutton"
    40.             android:onClick="sendFeedback"
    41.             android:layout_width="385dp">
    42.         </Button>
    43.     </LinearLayout>
    44. </ScrollView>
    45.  
    However, it takes issue with relative layouts and other linear layouts.
     
  7. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,292
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,292
    10,403
    1,988
    Male
    Software developer
    South West of England
    Even more bizarre! Do you get any issues reported by the UI designer in Android Studio for the layout that doesn't display?
    When running the app are there any errors in the log?
     

Share This Page

Loading...