1 Replies - 178 Views - Last Post: 26 March 2019 - 10:49 AM

#1 Rana Rizwan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-March 19

myapp has stopped error , when ever i try to run this app i get this

Posted 26 March 2019 - 10:44 AM

ACTIVITY MAIN XML FILE

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/list1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>
:code:




ROW XML FILE

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center">
    <ImageView
        android:id="@+id/logo"
        android:src="@mipmap/ic_launcher_round"
        android:layout_width="100dp"
        android:layout_height="100dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        
        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="18sp"
            android:textStyle="bold"/>
        <TextView
            android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Sub Title"
            android:textSize="18sp"
            android:textStyle="bold"/>
    </LinearLayout>

</LinearLayout>
:code:



MAIN ACTIVITY JAVA FILE


package com.example.rizwan_assg_01;

import android.content.Context;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    ListView list ;
    String title[] = {"Title One " , "Title Two " , "Title Three " , "Title Four " , "Title Five " };
    String sub_title[] = {" Sub Title One " , " Sub Title Two " , " Sub Title Three " , " Sub Title Four " , " Sub Title Five " };
    int img[] = {R.drawable.twitter , R.drawable.youtube , R.drawable.whatsapp , R.drawable.download ,R.drawable.insta };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        list.findViewById(R.id.list1);
        Myadapter myadapter = new Myadapter( this , title , img , sub_title );
        list.setAdapter(myadapter);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });
    }





    class Myadapter extends ArrayAdapter<String>
    {
        Context context;
        String Mytitle[];
        String Mysubtitle[];
        int myimg[];
         Myadapter(Context c , String[] t ,  int[] i, String[] s_t   )
         {
             super(c , R.layout.row , R.id.text1,t );
             this.context = c ;
             this.Mytitle = t;
             this.Mysubtitle = s_t;
             this.myimg = i;

         }


         public View getView(int pos  , View ConvertView , ViewGroup parent)
         {
             LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             View row = layoutInflater.inflate(R.layout.row , parent , false);
             ImageView images = row.findViewById(R.id.logo);
             TextView titles = row.findViewById(R.id.text1);
             TextView subtitles = row.findViewById(R.id.text2);
             images.setImageResource(myimg[pos]);
             titles.setText(Mytitle[pos]);
             subtitles.setText(Mysubtitle[pos]);

             return row;
         }
    }
}
:code:

This post has been edited by modi123_1: 26 March 2019 - 10:49 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: myapp has stopped error , when ever i try to run this app i get this

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,197
  • Joined: 12-June 08

Re: myapp has stopped error , when ever i try to run this app i get this

Posted 26 March 2019 - 10:49 AM

Please copy/paste your error message here and explain where you are running this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1