Android 具有可绘制文件夹中的图像的Listview正在播放或延迟

Android 具有可绘制文件夹中的图像的Listview正在播放或延迟,android,listview,drawable,lag,Android,Listview,Drawable,Lag,大家好。这是我的密码。我的listview在上下滚动后变得越来越慢,然后应用程序被关闭。只是想澄清一下。。。我有2个文本视图、1个图像视图和1个搜索字段。我的listview有100多个带有图片的项目 这是我的密码。为了方便起见,我只放了两个项目。我应该放什么?放在哪里?我是个新手。救救我 package com.example.exemplo; import java.util.ArrayList; import java.util.Arrays; import android.app.A

大家好。这是我的密码。我的listview在上下滚动后变得越来越慢,然后应用程序被关闭。只是想澄清一下。。。我有2个文本视图、1个图像视图和1个搜索字段。我的listview有100多个带有图片的项目

这是我的密码。为了方便起见,我只放了两个项目。我应该放什么?放在哪里?我是个新手。救救我

package com.example.exemplo;

import java.util.ArrayList;
import java.util.Arrays;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class Listagem extends Activity
{



EditText edittext;
ListView listview;

String[] text;

String[] text2;


int[] image = {
        R.drawable.wolf;
        R.drawable.cat;

    };

int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<String> text2_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();

public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

text =  getResources().getStringArray(R.array.text);
text2 = getResources().getStringArray(R.array.text2);



edittext = (EditText) findViewById(R.id.EditText01);
listview = (ListView) findViewById(R.id.ListView01);



listview.setOnItemClickListener(new OnItemClickListener(){

public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {


    if ("Howl".equals(text[position])) {
        MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
        player.start();


       }


    if ("Meow".equals(text[position])) {
        MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
        player.start();            
}

        });






listview.setAdapter(new MyCustomAdapter(text, text2, image));

edittext.addTextChangedListener(new TextWatcher()
{

public void afterTextChanged(Editable s)
{

}

public void beforeTextChanged(CharSequence s, int start,
int count, int after)
{

}

public void onTextChanged(CharSequence s, int start,
int before, int count)
{

textlength = edittext.getText().length();
text_sort.clear();
text2_sort.clear();
image_sort.clear();

for (int i = 0; i < text.length; i++)
{
if (textlength <= text[i].length())
{
if (edittext.getText().toString().
equalsIgnoreCase((String) text[i].subSequence(0, textlength)))
{
text_sort.add(text[i]);
text2_sort.add(text2[i]);
image_sort.add(image[i]);
}
}
}


listview.setOnItemClickListener(new OnItemClickListener(){

public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {


    if ("Howl".equals(text_sort.get(position))) {
        MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
        player.start();


       }


    if ("Meow".equals(text_sort.get(position))) {
        MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
        player.start();


       }

}

        });

listview.setAdapter(new MyCustomAdapter
(text_sort, text2_sort, image_sort));

}


});
}



class MyCustomAdapter extends BaseAdapter
{

String[] data_text;
String[] data_text2;
int[] data_image;

MyCustomAdapter()
{

}

MyCustomAdapter(String[] text, String[] text2, int[] image)
{
data_text = text;
data_text2 = text2;
data_image = image;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<String> text2, ArrayList<Integer>   image)
{
data_text = new String[text.size()];
data_text2 = new String[text2.size()];
data_image = new int[image.size()];

for(int i=0;i<text.size();i++)
{
data_text[i] = text.get(i);
data_text2[i] = text2.get(i);
data_image[i] = image.get(i);
}

}

public int getCount()
{
return data_text.length;

}

public String getItem(int position)
{
return null;
}

public long getItemId(int position)
{
return position;
}

public View getView(int position, View convertView, ViewGroup parent)
{

LayoutInflater inflater = getLayoutInflater();
View row;

row = inflater.inflate(R.layout.listview, parent, false);

listview.setCacheColorHint(Color.TRANSPARENT);
listview.setFastScrollEnabled(true);
listview.setScrollingCacheEnabled(false);

TextView textview = (TextView) row.findViewById(R.id.TextView01);

TextView textview2 = (TextView) row.findViewById(R.id.TextView02);
Typeface font1 = Typeface.createFromAsset(getAssets(), "arial.ttf");  
textview2.setTypeface(font1);
ImageView imageview = (ImageView) row
.findViewById(R.id.ImageView01);

textview.setText(data_text[position]);
textview2.setText(data_text2[position]);
imageview.setImageResource(data_image[position]);

return (row);

}
}

}

这是一个很好的实践使用视图持有人和检查出教程这将有助于你。嗯,我不知道如何做到这一点。我无法在代码中使用视图持有者。。。有人能帮我吗?我试过了。但我是个新手。。。所以,如果有人帮我纠正这一点,我会很感激的@用户1550421您不能使用它是什么意思?你当然可以。检查链接,或者简单地搜索ListView视图持有者模式以获取更多信息。