Listview不会在tabhost中滚动

时间:2013-08-12 10:03:14

标签: android listview scrollview android-tabhost

在我的应用程序中,我有tabhost,我在其中显示列表视图。我无法滚动我的列表视图,当我尝试滚动列表视图的颜色但不滚动。这里是图片 enter image description here

当我尝试滚动其颜色变化时

enter image description here

我的SearchDictionaryActivity.java是

public class SearchDictionaryActivity extends Activity{
    Intent intent;
    // Progress Dia//Log
    private ProgressDialog pDialog;
    DataHolder obj;
    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();
    private boolean enablePopup = true;

    // Listview Adapter
    ArrayAdapter<String> adapter;

    //ArrayList<String> categories=new ArrayList<String>();

    // catgories JSON url
    private static String url_all_products;

    // JSON Node names It should be same on srver(encodeing) and client(decoding)
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_products = "Products";
    private static final String TAG_Image = "Image";

    private static final String TAG_NAME = "name";
    // category JSONArray
    JSONArray category = null;
    // flag for Internet connection status
Boolean isInternetPresent = false;

EditText edittext;
ListView listview;

ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<Bitmap> image_sort = new ArrayList<Bitmap>();

String  ITEMTITLE ="HasMapValue";
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_dictionary);

    url_all_products=getString(R.string.url_ip);
    url_all_products=url_all_products+"get_list_of_name_of_products.php";
    new LoadCategories().execute();
    edittext = (EditText) findViewById(R.id.EditText01);
    listview = (ListView) findViewById(R.id.ListView01);



}



/**
 * Background Async Task to Load all catgories by making HTTP Request
 * */
class LoadCategories extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    Bitmap decodedByte;
    //ArrayList<HashMap<String, Object>> productsList=new ArrayList<HashMap<String,Object>>();
    String[] text = new String[0];
    Bitmap[] image = new Bitmap[0];


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(SearchDictionaryActivity.this);
        pDialog.setMessage("Loading ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    /**
     * getting catgories JSON
     * */
    protected String doInBackground(String... args) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        // getting JSON string from URL
        JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);

        // Check your log cat for JSON reponse
        //Log.d("All Products: ", json.toString());

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // products found
                // Getting Array of Categorys
                category = json.getJSONArray(TAG_products);
                //Log.i("category  ", category.toString());
                //Log.i("Lengt Category"," " +category.length());
                // looping through All Categories
                for (int i = 0; i < category.length(); i++) {
                    JSONObject c = category.getJSONObject(i);
                    //Log.i("JSONObject  ", c.toString());

                    // Storing each json item in variable
                    String name = c.getString(TAG_NAME);
                    String ProductImage = c.getString(TAG_Image);

                    //Log.i("StrineName  ", name);

                    byte[] decodedString = Base64.decode(ProductImage, Base64.DEFAULT);
                    decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 

                    //HashMap<String, Object> map = new HashMap<String, Object>();
                    text=reallocation(text);
                    image=reallocation_BitMap(image);

                    text[i]=name.toString().toLowerCase();
                    image[i]=decodedByte;


                }
            } else {
                // no products found
                // Launch Add New product Activity
                /*Intent i = new Intent(getApplicationContext(),
                                        NewProductActivity.class);
                                // Closing all previous activities
                                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(i);*/
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }



    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        //
        if (pDialog.isShowing()) {
            pDialog.dismiss();
            // progressDialog.setCancelable(true);
        }


        edittext.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                int textlength = edittext.getText().length();
                text_sort.clear();
                image_sort.clear();
                if (s.length() >= 1 && enablePopup) {


                    //Log.i("Length of SorttEX111"," "+ text_sort.size());

                    for( int i=0;i<text.length;i++)
                    {

                        if((s.toString().toLowerCase()).equalsIgnoreCase(((String) text[i].subSequence(0, textlength))))
                        {

                            text_sort.add(text[i]);
                            image_sort.add(image[i]);
                        }

                    }
                }

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

                enablePopup = true;
            }

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

            }

            public void afterTextChanged(Editable s) {
            }
        });

    }

}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = this.getMenuInflater();
    menuInflater.inflate(R.menu.item_menu, menu);

    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (((String) item.getTitle()).compareTo("About") == 0) {

        return true;
    }

    return super.onOptionsItemSelected(item);
}












public class DataHolder 

{
    String ProductName;
    Bitmap Productimage;



    public void setData(String ProductName,Bitmap image)
    {
        this.ProductName=ProductName;
        this.Productimage=image;


    }

    public String GetProductName()
    {return ProductName;}

    public Bitmap Getimage()
    {return Productimage;}

}


public class DataHolder1 

{
    String ProductName;
    Bitmap Productimage;



    public void setData1(String ProductName,Bitmap image)
    {
        this.ProductName=ProductName;
        this.Productimage=image;


    }

    public String GetProductName1()
    {return ProductName;}

    public Bitmap Getimage1()
    {return Productimage;}

}

class MyCustomAdapter extends BaseAdapter
{

    String[] data_text;
    Bitmap[] data_image;

    MyCustomAdapter()
    {

        data_text=null;
        data_image=null;
    }

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

        for(int i=0;i<text.size();i++)
        {
            data_text[i] = text.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) {

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.search_dictionary_item, null);
        }

        TextView textview = (TextView) convertView.findViewById(R.id.TextView01);
        ImageView imageview = (ImageView) convertView.findViewById(R.id.ImageView01);

        textview.setText(data_text[position]);
        imageview.setImageBitmap(data_image[position]);

        return convertView;

    }
}


public static String[] reallocation(String s[])
{
    String t[]=new String[s.length+1];
    for(int i=0; i<s.length;i++)
    {

        t[i]=s[i];
    }
    return t;
}
public static Bitmap[] reallocation_BitMap(Bitmap s[])
{
    Bitmap t[]=new Bitmap[s.length+1];
    for(int i=0; i<s.length;i++)
    {

            t[i]=s[i];
        }
        return t;
    }

}

和search_dictionary.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@color/green">

    <EditText
        android:id="@+id/EditText01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Search" >
    </EditText>

    <ListView
    android:id="@+id/ListView01"
    android:layout_width="fill_parent"
    android:layout_height="0dip" 
    android:layout_weight="50">
</ListView>

1 个答案:

答案 0 :(得分:1)

我通过在{xml

中放置android:cacheColorHint="#00000000"找到了答案
<ListView
            android:id="@+id/List_Of_Categories"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:cacheColorHint="#00000000"
            android:divider="@android:color/transparent"
            android:dividerHeight="1dp"
             />