﻿define('DISALLOW_FILE_EDIT', true);
define('DISALLOW_FILE_MODS', true);<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>/dev/head &#187; listview</title>
	<atom:link href="http://devhead.ru/cat/listview/feed" rel="self" type="application/rss+xml" />
	<link>http://devhead.ru</link>
	<description>Статьи и видео уроки</description>
	<lastBuildDate>Mon, 30 Jan 2017 11:12:34 +0000</lastBuildDate>
	<language>ru-RU</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.37</generator>
	<item>
		<title>ListView with image from file</title>
		<link>http://devhead.ru/read/listview-with-text-and-image</link>
		<comments>http://devhead.ru/read/listview-with-text-and-image#comments</comments>
		<pubDate>Thu, 22 May 2014 09:38:52 +0000</pubDate>
		<dc:creator><![CDATA[Аноним]]></dc:creator>
				<category><![CDATA[Статьи]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[listview]]></category>

		<guid isPermaLink="false">http://devhead.ru/read/listview-with-text-and-image</guid>
		<description><![CDATA[MainActivity.java package ru.devhead.flashcardsen_ru.app; import android.database.Cursor; import android.database.MatrixCursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v4.app.FragmentActivity; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.support.v4.widget.SimpleCursorAdapter; import android.view.Menu; import android.widget.ImageView; import android.widget.ListView; import java.util.ArrayList; public class MainActivity extends FragmentActivity implements LoaderCallbacks&#60;Cursor&#62; { String[] text = { "Afghanistan", "Algeria" }; Bitmap [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="http://devhead.ru/read/listview-with-text-and-image/attachment/customlistviewss" rel="attachment wp-att-2042"><img class="size-medium wp-image-2042 alignnone" alt="customlistviewss" src="http://devhead.ru/wp-content/uploads/2014/05/customlistviewss-300x278.png" width="300" height="278" /></a></p>
<p><span id="more-2039"></span></p>
<p>MainActivity.java</p>
<pre class="brush: java">package ru.devhead.flashcardsen_ru.app;

import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.ListView;

import java.util.ArrayList;

public class MainActivity extends FragmentActivity implements LoaderCallbacks&lt;Cursor&gt; {

    String[] text = { "Afghanistan", "Algeria" };

    Bitmap bmp = BitmapFactory.decodeFile("/mnt/sdcard/cards/cat.png");
    Bitmap bmp1 = BitmapFactory.decodeFile("/mnt/sdcard/cards/dog.png");
    Bitmap[] image={bmp,bmp1};

    // int [] image = {  R.drawable.ic_launcher,R.drawable.ic_launcher};

    ListItemDetails item_details;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArrayList&lt;ListItemDetails&gt; result = GetSearchResults();
        ListView lv = (ListView)findViewById(R.id.listView);
        lv.setAdapter(new CustomListAdapter(result,getApplicationContext()));

    }
    private ArrayList&lt;ListItemDetails&gt; GetSearchResults() {
        // TODO Auto-generated method stub
        ArrayList&lt;ListItemDetails&gt; results = new ArrayList&lt;ListItemDetails&gt;();
        ImageView imageview = (ImageView) findViewById(R.id.imageView1);

        for(int i=0;i&lt;text.length;i++)
        {
            item_details= new ListItemDetails();
            item_details.setName(text[i]);
            item_details.setImage(image[i]);
            results.add(item_details);
        }

        return results;
    }

    @Override
    public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) {
        return null;
    }

    @Override
    public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) {

    }

    @Override
    public void onLoaderReset(Loader&lt;Cursor&gt; loader) {

    }
}</pre>
<p>&nbsp;</p>
<p>CustomListAdapter.java</p>
<pre class="brush: java">package ru.devhead.flashcardsen_ru.app;

        import java.util.ArrayList;
        import android.app.Activity;
        import android.content.Context;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.BaseAdapter;
        import android.widget.ImageView;
        import android.widget.TextView;

public class CustomListAdapter extends BaseAdapter {

    private static ArrayList&lt;ListItemDetails&gt; itemDetailsrrayList;

    LayoutInflater layoutInflator;
    String[] countryName;
    int[] countryFlag;
    Context context;

    public CustomListAdapter(ArrayList&lt;ListItemDetails&gt; result, Context c) {
        // TODO Auto-generated constructor stub
        itemDetailsrrayList = result;
        context = c;
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return itemDetailsrrayList.size();
    }

    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return itemDetailsrrayList.get(arg0);
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        layoutInflator =
                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = layoutInflator.inflate(R.layout.item_list, parent, false);

        TextView textview = (TextView) row.findViewById(R.id.textView1);
        ImageView imageview = (ImageView) row.findViewById(R.id.imageView1);

        textview.setText(itemDetailsrrayList.get(position).getName());
        imageview.setImageBitmap(itemDetailsrrayList.get(position).getImage());

        return (row);
    }
}</pre>
<p>ListItemDetails.java</p>
<pre class="brush: java">package ru.devhead.flashcardsen_ru.app;

import android.graphics.Bitmap;

public class ListItemDetails {

    private String name;
    private Bitmap image;

    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name = name;
    }
    public Bitmap getImage()
    {
        return image;
    }
    public void setImage(Bitmap images)
    {
        this.image = images;
    }
}</pre>
<p>layout/activity_main.xml</p>
<pre class="brush: xhtml">&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="ru.devhead.flashcardsen_ru.app.MainActivity"&gt;

    &lt;ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/listView"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" /&gt;

&lt;/RelativeLayout&gt;</pre>
<p>layout/item_list.xml</p>
<pre class="brush: xhtml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" &gt;

    &lt;LinearLayout
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dip"&gt;

        &lt;ImageView
            android:id="@+id/imageView1"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:src="@drawable/ic_launcher" /&gt;

        &lt;TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dip"
            android:layout_marginTop="8dip"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000" /&gt;

    &lt;/LinearLayout&gt;

&lt;/LinearLayout&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://devhead.ru/read/listview-with-text-and-image/feed</wfw:commentRss>
		<slash:comments>160</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->