没有得到显示singleitem视图 [英] Nothing getting displayed in singleitem view

查看:213
本文介绍了没有得到显示singleitem视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有检索解析和显示信息到一个列表视图的应用程序,但是当应用程序被运行,并且单击列表视图项它会打开一个新的活动,并从parse.com显示一些图像和文字,但它显示什么像下面

图片

下面是我的code

主要activity.java

 公共类MainActivity扩展活动
{
ListView控件列表视图;
清单<&的parseObject GT; OB;
ProgressDialog mProgressDialog;
FinalAdapter适配器;
私人列表< codeLIST> codeLIST = NULL;
@覆盖
保护无效的onCreate(捆绑savedInstanceState)
{
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.beg_layout);    新RemoteDataTask()执行();
}私有类RemoteDataTask扩展的AsyncTask<太虚,太虚,太虚>
{
    @覆盖
    在preExecute保护无效(){
        super.on preExecute();
        //创建一个progressdialog
        mProgressDialog =新ProgressDialog(MainActivity.this);
        //设置progressdialog称号
        mProgressDialog.setTitle(测试);
        //设置progressdialog消息
        mProgressDialog.setMessage(Loading请稍候,这可能需要一些时间......);
        mProgressDialog.setIndeterminate(真);
        //显示progressdialog
        mProgressDialog.show();
    }
    @覆盖
    保护无效doInBackground(无效... PARAMS)
    {
        codeLIST =新的ArrayList< codeLIST>();
        尝试{
            ParseQuery<&的parseObject GT;查询=新ParseQuery<&的parseObject GT;(
                BeginnerActivity);
            query.orderByAscending(_ created_at);
            OB = query.find();
            对于(的parseObject begactivity:OB){                ParseFile listimg =(ParseFile)begactivity.get(alphabetimg);
                ParseFile levelimg =(ParseFile)begactivity.get(levelimg);
                ParseFile apiimg =(ParseFile)begactivity.get(apiimg);
                ParseFile descimgone =(ParseFile)begactivity.get(descimgone);
                ParseFile descimgtwo =(ParseFile)begactivity.get(descimgtwo);
                codeLIST地图=新的codeLIST();
                map.setListHeading((字符串)begactivity.get(listheading));
                map.setSingleItemHeading((字符串)begactivity.get(标题));
                map.setDescription((字符串)begactivity.get(副标题));
                map.setApiText((字符串)begactivity.get(apitext));
                map.setFinal codeTEXT((字符串)begactivity.get(codeTEXT));                map.setAlphabetimg(listimg.getUrl());
                map.setLevelImg(levelimg.getUrl());
                map.setApiImg(apiimg.getUrl());
                map.set previewImgOne(descimgone.getUrl());
                map.set previewImgTwo(descimgtwo.getUrl());
                codelist.add(图)
            }
        }赶上(ParseException的E){
            Log.e(错误,e.getMessage());
            e.printStackTrace();        }
        返回null;
    }    @覆盖
    保护无效onPostExecute(虚空结果){
        //定位listview_main.xml列表视图
        列表视图=(ListView控件)findViewById(R.id.beg_layoutListView);
        //将结果传递到ListViewAdapter.java
        适配器=新FinalAdapter(MainActivity.this,
                                   codeLIST);
        //绑定适配器到ListView
        listview.setAdapter(适配器);
        //关闭progressdialog
        mProgressDialog.dismiss();
    }}}

codelist.java

 公共类codeLIST
{
私人字符串alphabetimg;
私人字符串listHeading;
私人字符串levelImg;
私人字符串singleItemHeading;
私人字符串描述;
私人字符串apiImg;
私人字符串apiText;私人字符串previewImgOne;
私人字符串previewImgTwo;
私人字符串最后codeTEXT;公共无效setAlphabetimg(字符串alphabetimg)
{
    this.alphabetimg = alphabetimg;
}公共字符串getAlphabetimg()
{
    返回alphabetimg;
}公共无效setListHeading(字符串listHeading)
{
    this.listHeading = listHeading;
}公共字符串getListHeading()
{
    返回listHeading;
}公共无效setLevelImg(字符串levelImg)
{
    this.levelImg = levelImg;
}公共字符串getLevelImg()
{
    返回levelImg;
}公共无效setSingleItemHeading(字符串singleItemHeading)
{
    this.singleItemHeading = singleItemHeading;
}公共字符串getSingleItemHeading()
{
    返回singleItemHeading;
}公共无效setDescription(字符串描述)
{
    this.description =描述;
}公共字符串getDescription()
{
    返回描述;
}公共无效setApiImg(字符串apiImg)
{
    this.apiImg = apiImg;
}公共字符串getApiImg()
{
    返回apiImg;
}公共无效setApiText(字符串apiText)
{
    this.apiText = apiText;
}公共字符串getApiText()
{
    返回apiText;
}
公共无效集previewImgOne(字符串previewImgOne)
{
    这previewImgOne = previewImgOne。
}公共字符串获得previewImgOne()
{
    返回previewImgOne;
}公共无效集previewImgTwo(字符串previewImgTwo)
{
    这previewImgTwo = previewImgTwo。
}公共字符串的get previewImgTwo()
{
    返回previewImgTwo;
}公共无效setFinal codeTEXT(字符串最后codeTEXT)
{
    this.final codeTEXT =最终codeTEXT;
}公共字符串getFinal codeTEXT()
{
    最后返回codeTEXT;
}}

解析application.java

 公共类ParseApplication扩展应用{@覆盖
公共无效的onCreate(){
    super.onCreate();    //此处添加您的初始code
    Parse.initialize(这一点,4rOrqK23m0nVq187Of3rhDe0TK1R7FObdBWhfX10,afKA4B9ohvk3M9pZNv9qK2ypbrdOpXi0FPnrXOu6);    ParseUser.enableAutomaticUser();
    ParseACL defaultACL =新ParseACL();    //如果你想所有对象是默认私人,删除此行。
    defaultACL.setPublicReadAccess(真);    ParseACL.setDefaultACL(defaultACL,真);
} }

最后adapter.java

 公共类FinalAdapter延伸BaseAdapter
{
上下文语境;
    LayoutInflater吹气;
    ImageLoader的ImageLoader的;
私人列表< codeLIST> codeLIST = NULL;
私人的ArrayList< codeLIST> ArrayList的;公共FinalAdapter(上下文的背景下,
                    清单< codeLIST> codeLIST){
    this.context =背景;
    这codeLIST = codeLIST;
    充气= LayoutInflater.from(上下文);
    this.arraylist =新的ArrayList< codeLIST>();
    this.arraylist.addAll(codeLIST);
    ImageLoader的=新ImageLoader的(上下文);}公共类ViewHolder {
    TextView的listHeading;
    ImageView的alphabetList;
}
@覆盖
公众诠释getCount将()
{
    返回codeList.size();
}@覆盖
公共对象的getItem(INT位置)
{
    返回codeList.get(位置);
}@覆盖
众长getItemId(INT位置)
{
    返回的位置;
}@覆盖
公共查看getView(最终诠释的立场,观点来看,父母的ViewGroup)
{
    最后ViewHolder持有人;
    如果(查看== NULL){
        持有人=新ViewHolder();
        鉴于= inflater.inflate(R.layout.beg_list_item,NULL);
        holder.listHeading =(TextView中)view.findViewById(R.id.beg_list_itemTextView);
        holder.alphabetList =(ImageView的)view.findViewById(R.id.beg_list_itemImageView);
        view.setTag(保持器);    }其他{
        支架=(ViewHolder)view.getTag();
    }
    holder.listHeading.setText(codeList.get(位置).getListHeading());
    imageLoader.DisplayImage(codeList.get(位置).getAlphabetimg()
                             holder.alphabetList);    view.setOnClickListener(新OnClickListener(){            @覆盖
            公共无效的onClick(查看为arg0){
                意向意图=新意图(背景下,SingleItemView.class);                intent.putExtra(listheading
                                (codeList.get(位置).getListHeading()));
                intent.putExtra(alphabetimg
                                (codeList.get(位置).getAlphabetimg()));
                //开始SingleItemView类
                context.startActivity(意向);            }
        });    返回视图。
} }

singleitemview.java

 公共类SingleItemView扩展了活动。
{
    字符串标题;
    串副标题;
    串levelImg;
串apiImg;
    串apiText;
    串descImgOne;
    串descImgTwo;
字符串codeTEXT;
ImageLoader的imgloader =新ImageLoader的(本);@覆盖
保护无效的onCreate(捆绑savedInstanceState)
{
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.singleitemview);    意向I = getIntent();    标题= i.getStringExtra(标题);
    副标题= i.getStringExtra(副标题);
    levelImg = i.getStringExtra(levelimg);
    apiImg = i.getStringExtra(apiimg);
    apiText = i.getStringExtra(apitext);
    descImgOne = i.getStringExtra(descimgone);
    descImgTwo = i.getStringExtra(descimgtwo);
    codeTEXT = i.getStringExtra(codeTEXT);
    TextView的headingtxt =(的TextView)findViewById(R.id.singleitemheading);
    TextView的subheadingtxt =(的TextView)findViewById(R.id.singleitemsubheading);
    TextView的apitxt =(的TextView)findViewById(R.id.singleitemviewapitext);
    TextView的codetxt =(的TextView)findViewById(R.id.singleitemview codeTEXT);    ImageView的水平=(ImageView的)findViewById(R.id.levelimg);
    ImageView的API =(ImageView的)findViewById(R.id.singleitemviewapiimg);
    ImageView的descone =(ImageView的)findViewById(R.id.descriptionimgone);
    ImageView的desctwo =(ImageView的)findViewById(R.id.descriptionimgtwo);    headingtxt.setText(航向);
    subheadingtxt.setText(小标题);
    apitxt.setText(apiText);
    codetxt.setText(codeTEXT);    imgloader.DisplayImage(levelImg,水平);
    imgloader.DisplayImage(apiImg,API);
    imgloader.DisplayImage(descImgOne,descone);
    imgloader.DisplayImage(descImgTwo,desctwo);}
 }

图片loaded.java

 公共类ImageLoader的{的MemoryCache的MemoryCache =新的MemoryCache();
FileCache fileCache;
私人地图< ImageView的,字符串> imageViews =集合
.synchronizedMap(新的WeakHashMap< ImageView的,字符串>());
ExecutorService的ExecutorService的;
//处理程序,以显示在UI线程图片
处理程序处理程序=新的处理程序();公共ImageLoader的(上下文的背景下){
    fileCache =新FileCache(背景);
    ExecutorService的= Executors.newFixedThreadPool(5);
}最终诠释stub_id = R.drawable.temp_img;公共无效DisplayImage(字符串URL,ImageView的ImageView的){
    imageViews.put(ImageView的,URL);
    位图位图= memoryCache.get(URL);
    如果(位图!= NULL)
        imageView.setImageBitmap(位图);
    其他{
        queuePhoto(URL,ImageView的);
        imageView.setImageResource(stub_id);
    }
}私人无效queuePhoto(字符串URL,ImageView的ImageView的){
    PhotoToLoad P =新PhotoToLoad(URL,ImageView的);
    executorService.submit(新PhotosLoader(P));
}私人位图getBitmap(字符串URL){
    文件F = fileCache.getFile(URL);    位图B =去codeFILE(F);
    如果(B!= NULL)
        返回b;    从网上下载//图片
    尝试{
        位图位图= NULL;
        URL =图片网址新的URL(网址);
        HttpURLConnection的康恩=(HttpURLConnection类)图片网址
            .openConnection();
        conn.setConnectTimeout(30000);
        conn.setReadTimeout(30000);
        conn.setInstanceFollowRedirects(真);
        InputStream为= conn.getInputStream();
        OutputStream的OS =新的FileOutputStream(F);
        Utils.CopyStream(是,OS);
        os.close();
        conn.disconnect();
        位=去codeFILE(F);
        返回位图;
    }赶上(Throwable的前){
        ex.printStackTrace();
        如果(前的instanceof的OutOfMemoryError)
            memoryCache.clear();
        返回null;
    }
}//德$ C $连拍影像的鳞它来减少内存消耗
私人位图德codeFILE(文件f){
    尝试{
        //德code图像尺寸
        BitmapFactory.Options O =新BitmapFactory.Options();
        o.inJustDe codeBounds = TRUE;
        的FileInputStream流1 =新的FileInputStream(F);
        BitmapFactory.de codeStream(STREAM1,空,O);
        stream1.close();        //找到正确的比例值。它应该是2的幂。
        最终诠释REQUIRED_SIZE = 70;
        INT width_tmp = o.outWidth,height_tmp = o.outHeight;
        int标= 1;
        而(真){
            如果(width_tmp / 2'; REQUIRED_SIZE
                || height_tmp / 2'; REQUIRED_SIZE)
                打破;
            width_tmp / = 2;
            height_tmp / = 2;
            规模* = 2;
        }        //德code。与inSampleSize
        BitmapFactory.Options O2 =新BitmapFactory.Options();
        o2.inSampleSize =规模;
        流2的FileInputStream =新的FileInputStream(F);
        位图位图= BitmapFactory.de codeStream(流2,空,O2);
        stream2.close();
        返回位图;
    }赶上(FileNotFoundException异常五){
    }赶上(IOException异常五){
        e.printStackTrace();
    }
    返回null;
}//任务队列
私有类PhotoToLoad {
    公共字符串的URL;
    公共ImageView的ImageView的;    公共PhotoToLoad(字符串U,ImageView的我){
        URL = U;
        ImageView的= I;
    }
}类PhotosLoader实现Runnable {
    PhotoToLoad photoToLoad;    PhotosLoader(PhotoToLoad photoToLoad){
        this.photoToLoad = photoToLoad;
    }    @覆盖
    公共无效的run(){
        尝试{
            如果(imageViewReused(photoToLoad))
                返回;
            BMP位图= getBitmap(photoToLoad.url);
            memoryCache.put(photoToLoad.url,BMP);
            如果(imageViewReused(photoToLoad))
                返回;
            BitmapDisplayer BD =新BitmapDisplayer(BMP,photoToLoad);
            handler.post(BD);
        }赶上(的Throwable日){
            th.printStackTrace();
        }
    }
}布尔imageViewReused(PhotoToLoad photoToLoad){
    字符串标记= imageViews.get(photoToLoad.imageView);
    如果(标记== NULL ||!tag.equals(photoToLoad.url))
        返回true;
    返回false;
}//用在UI线程来显示位图
类BitmapDisplayer实现Runnable {
    位图位图;
    PhotoToLoad photoToLoad;    公共BitmapDisplayer(位图B,PhotoToLoad P){
        位= B;
        photoToLoad = P;
    }    公共无效的run(){
        如果(imageViewReused(photoToLoad))
            返回;
        如果(位图!= NULL)
            photoToLoad.imageView.setImageBitmap(位图);
        其他
            photoToLoad.imageView.setImageResource(stub_id);
    }
}公共无效clearCache(){
    memoryCache.clear();
    fileCache.clear();
}}

filecache.java

 公共类FileCache {私人文件cacheDir;公共FileCache(上下文的背景下){
    //查找目录保存缓存图像
    如果(android.os.Environment.getExternalStorageState()。等于(
            android.os.Environment.MEDIA_MOUNTED))
        cacheDir =新的文件(
            android.os.Environment.getExternalStorageDirectory(),
            ImgTxt);
    其他
        cacheDir = context.getCacheDir();
    如果(!cacheDir.exists())
        cacheDir.mkdirs();
}公开文件的GetFile(字符串URL){
    字符串文件名=将String.valueOf(url.hash code());
    //字符串文件名= URLEn coder.en code(URL);
    文件f =新的文件(cacheDir,文件名);
    返回F;}公共无效清除(){
    文件[] =文件cacheDir.listFiles();
    如果(文件== NULL)
        返回;
    对于(F文件:文件)
        f.delete();
}

}

memorycache.java

 公共类的MemoryCache {私有静态最后弦乐TAG =的MemoryCache;//最后一个参数如此LRU排序
私人地图<弦乐,位图>缓存=集合
.synchronizedMap(新LinkedHashMap的<弦乐,位图>(10,1.5F,真实));//当前分配的大小
私人长期的大小= 0;//最大内存字节
私人长期限制= 1000000;公众的MemoryCache(){
    //使用可用堆大小的25%
    setLimit(调用Runtime.getRuntime()maxMemory()/ 4);
}公共无效setLimit(长NEW_LIMIT){
    极限= NEW_LIMIT;
    Log.i(TAG的MemoryCache会使用到限+ / 1024/1024 +MB);
}公共位图的get(字符串ID){
    尝试{
        如果(!cache.containsKey(ID))
            返回null;
        返回cache.get(ID);
    }赶上(NullPointerException异常前){
        ex.printStackTrace();
        返回null;
    }
}公共无效认沽(字符串ID,位图位图){
    尝试{
        如果(cache.containsKey(ID))
            大小 - = getSizeInBytes(cache.get(ID));
        cache.put(ID,位图);
        大小+ = getSizeInBytes(位图);
        checkSize();
    }赶上(的Throwable日){
        th.printStackTrace();
    }
}私人无效checkSize(){
    Log.i(TAG,高速缓存大小=+尺寸+长度=+ cache.size());
    如果(大小>限制){
        //最近最少访问的项目将是第一个迭代
        迭代器<钥匙进入LT;弦乐,位图>> ITER = cache.entrySet()迭代器()。
        而(iter.hasNext()){
            进入<弦乐,位图>条目= iter.next();
            大小 - = getSizeInBytes(entry.getValue());
            iter.remove();
            如果(大小< =极限)
                打破;
        }
        Log.i(TAG,清洁缓存新的大小。+ cache.size());
    }
}公共无效清除(){
    尝试{
        cache.clear();
        大小= 0;
    }赶上(NullPointerException异常前){
        ex.printStackTrace();
    }
}长getSizeInBytes(位图位图){
    如果(位图== NULL)
        返回0;
    返回bitmap.getRowBytes()* bitmap.getHeight();
}
}

安卓的manifest.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.mycompany.myapp><使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/><应用
    机器人:名字=ParseApplication
    机器人:allowBackup =真
    机器人:图标=@绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <活动
        机器人:名字=。MainActivity
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
    <活动
        机器人:名字=SingleItemView。>
    < /活性GT;
< /用途>< /清单>


解决方案

在onclicklistener()添加此code

  intent.putExtra(levelimg
                            (codeList.get(位置).getLevelImg()));                    intent.putExtra(标题,
                            (codeList.get(位置).getSingleItemHeading()));                    intent.putExtra(副标题
                            (codeList.get(位置).getDescription()));                    intent.putExtra(apitext
                            (codeList.get(位置).getApiText()));                    intent.putExtra(apiimg
                            (codeList.get(位置).getApiImg()));                    intent.putExtra(descimgone
                            (codeList.get(位置)。获得previewImgOne()));                    intent.putExtra(descimgtwo
                            (codeList.get(位置)。获得previewImgTwo()));                    intent.putExtra(codeTEXT
                            (codeList.get(位置).getFinal codeTEXT()));

I am having an app that retrieves information from parse and display into a list view ,but when the app is run and the list view item is clicked it opens a new activity and display some images and text from parse.com but it shows nothing like the image below

Here is my code

main activity.java

public class MainActivity extends Activity 
{
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
FinalAdapter adapter;
private List<CodeList> codelist = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.beg_layout);

    new RemoteDataTask().execute();
}

private class RemoteDataTask extends AsyncTask<Void, Void, Void>
{
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(MainActivity.this);
        // Set progressdialog title
        mProgressDialog.setTitle("Testing");
        // Set progressdialog message
        mProgressDialog.setMessage("Loading. Please wait this may take few moments ....");
        mProgressDialog.setIndeterminate(true);
        // Show progressdialog
        mProgressDialog.show();
    }


    @Override
    protected Void doInBackground(Void... params)
    {
        codelist = new ArrayList<CodeList>();
        try{
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                "BeginnerActivity");
            query.orderByAscending("_created_at");
            ob = query.find();
            for(ParseObject begactivity : ob){

                ParseFile listimg = (ParseFile) begactivity.get("alphabetimg");
                ParseFile levelimg = (ParseFile) begactivity.get("levelimg");
                ParseFile apiimg = (ParseFile) begactivity.get("apiimg");
                ParseFile descimgone = (ParseFile) begactivity.get("descimgone");
                ParseFile descimgtwo = (ParseFile) begactivity.get("descimgtwo");


                CodeList map = new CodeList();
                map.setListHeading((String) begactivity.get("listheading"));
                map.setSingleItemHeading((String) begactivity.get("heading"));
                map.setDescription((String) begactivity.get("subheading"));
                map.setApiText((String) begactivity.get("apitext"));
                map.setFinalCodeText((String) begactivity.get("codetext"));

                map.setAlphabetimg(listimg.getUrl());
                map.setLevelImg(levelimg.getUrl());
                map.setApiImg(apiimg.getUrl());
                map.setPreviewImgOne(descimgone.getUrl());
                map.setPreviewImgTwo(descimgtwo.getUrl());
                codelist.add(map);
            }
        }catch(ParseException e){
            Log.e("Error", e.getMessage());
            e.printStackTrace();

        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // Locate the listview in listview_main.xml
        listview = (ListView) findViewById(R.id.beg_layoutListView);
        // Pass the results into ListViewAdapter.java
        adapter = new FinalAdapter(MainActivity.this,
                                   codelist);
        // Binds the Adapter to the ListView
        listview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
    }



}

}

codelist.java

public class CodeList
{
private String alphabetimg;
private String listHeading;
private String levelImg;
private String singleItemHeading;
private String description;
private String apiImg;
private String apiText;

private String previewImgOne;
private String previewImgTwo;
private String finalCodeText;



public void setAlphabetimg(String alphabetimg)
{
    this.alphabetimg = alphabetimg;
}

public String getAlphabetimg()
{
    return alphabetimg;
}

public void setListHeading(String listHeading)
{
    this.listHeading = listHeading;
}

public String getListHeading()
{
    return listHeading;
}

public void setLevelImg(String levelImg)
{
    this.levelImg = levelImg;
}

public String getLevelImg()
{
    return levelImg;
}

public void setSingleItemHeading(String singleItemHeading)
{
    this.singleItemHeading = singleItemHeading;
}

public String getSingleItemHeading()
{
    return singleItemHeading;
}

public void setDescription(String description)
{
    this.description = description;
}

public String getDescription()
{
    return description;
}

public void setApiImg(String apiImg)
{
    this.apiImg = apiImg;
}

public String getApiImg()
{
    return apiImg;
}

public void setApiText(String apiText)
{
    this.apiText = apiText;
}

public String getApiText()
{
    return apiText;
}


public void setPreviewImgOne(String previewImgOne)
{
    this.previewImgOne = previewImgOne;
}

public String getPreviewImgOne()
{
    return previewImgOne;
}

public void setPreviewImgTwo(String previewImgTwo)
{
    this.previewImgTwo = previewImgTwo;
}

public String getPreviewImgTwo()
{
    return previewImgTwo;
}

public void setFinalCodeText(String finalCodeText)
{
    this.finalCodeText = finalCodeText;
}

public String getFinalCodeText()
{
    return finalCodeText;
}

}

parse application.java

public class ParseApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    // Add your initialization code here
    Parse.initialize(this, "4rOrqK23m0nVq187Of3rhDe0TK1R7FObdBWhfX10", "afKA4B9ohvk3M9pZNv9qK2ypbrdOpXi0FPnrXOu6");

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();

    // If you would like all objects to be private by default, remove this line.
    defaultACL.setPublicReadAccess(true);

    ParseACL.setDefaultACL(defaultACL, true);
}

 }

final adapter.java

public class FinalAdapter extends BaseAdapter
{
Context context;
    LayoutInflater inflater;
    ImageLoader imageLoader;
private List<CodeList> codeList = null;
private ArrayList<CodeList> arraylist;

public FinalAdapter(Context context,
                    List<CodeList> codeList) {
    this.context = context;
    this.codeList = codeList;
    inflater = LayoutInflater.from(context);
    this.arraylist = new ArrayList<CodeList>();
    this.arraylist.addAll(codeList);
    imageLoader = new ImageLoader(context);

}

public class ViewHolder{
    TextView listHeading;
    ImageView alphabetList;
}


@Override
public int getCount()
{
    return codeList.size();
}

@Override
public Object getItem(int position)
{
    return codeList.get(position);
}

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

@Override
public View getView(final int position, View view, ViewGroup parent)
{
    final ViewHolder holder;
    if(view == null){
        holder = new ViewHolder();
        view = inflater.inflate(R.layout.beg_list_item,null);
        holder.listHeading = (TextView) view.findViewById(R.id.beg_list_itemTextView);
        holder.alphabetList = (ImageView) view.findViewById(R.id.beg_list_itemImageView);
        view.setTag(holder);

    }else{
        holder = (ViewHolder) view.getTag();
    }
    holder.listHeading.setText(codeList.get(position).getListHeading());
    imageLoader.DisplayImage(codeList.get(position).getAlphabetimg(),
                             holder.alphabetList);



    view.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0){
                Intent intent = new Intent(context, SingleItemView.class);

                intent.putExtra("listheading",
                                (codeList.get(position).getListHeading()));
                intent.putExtra("alphabetimg",
                                (codeList.get(position).getAlphabetimg()));
                // Start SingleItemView Class
                context.startActivity(intent);

            }
        });                 

    return view;
}

 }

singleitemview.java

public class SingleItemView extends Activity.  
{
    String heading;
    String subHeading;
    String levelImg;
String apiImg;
    String apiText;
    String descImgOne;
    String descImgTwo;
String codeText;
ImageLoader imgloader = new ImageLoader(this);

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

    Intent i = getIntent();

    heading= i.getStringExtra("heading");
    subHeading = i.getStringExtra("subheading");
    levelImg = i.getStringExtra("levelimg");
    apiImg = i.getStringExtra("apiimg");
    apiText = i.getStringExtra("apitext");
    descImgOne = i.getStringExtra("descimgone");
    descImgTwo = i.getStringExtra("descimgtwo");
    codeText = i.getStringExtra("codetext");


    TextView headingtxt = (TextView)findViewById(R.id.singleitemheading);
    TextView subheadingtxt = (TextView)findViewById(R.id.singleitemsubheading);
    TextView apitxt = (TextView)findViewById(R.id.singleitemviewapitext);
    TextView codetxt = (TextView) findViewById(R.id.singleitemviewcodetext);

    ImageView level =(ImageView) findViewById(R.id.levelimg);
    ImageView api =(ImageView) findViewById(R.id.singleitemviewapiimg);
    ImageView descone =(ImageView) findViewById(R.id.descriptionimgone);
    ImageView desctwo =(ImageView) findViewById(R.id.descriptionimgtwo);

    headingtxt.setText(heading);
    subheadingtxt.setText(subHeading);
    apitxt.setText(apiText);
    codetxt.setText(codeText);

    imgloader.DisplayImage(levelImg, level);
    imgloader.DisplayImage(apiImg, api);
    imgloader.DisplayImage(descImgOne, descone);
    imgloader.DisplayImage(descImgTwo, desctwo);

}
 }

image loaded.java

public class ImageLoader {

MemoryCache memoryCache = new MemoryCache();
FileCache fileCache;
private Map<ImageView, String> imageViews = Collections
.synchronizedMap(new WeakHashMap<ImageView, String>());
ExecutorService executorService;
// Handler to display images in UI thread
Handler handler = new Handler();

public ImageLoader(Context context) {
    fileCache = new FileCache(context);
    executorService = Executors.newFixedThreadPool(5);
}

final int stub_id = R.drawable.temp_img;

public void DisplayImage(String url, ImageView imageView) {
    imageViews.put(imageView, url);
    Bitmap bitmap = memoryCache.get(url);
    if (bitmap != null)
        imageView.setImageBitmap(bitmap);
    else {
        queuePhoto(url, imageView);
        imageView.setImageResource(stub_id);
    }
}

private void queuePhoto(String url, ImageView imageView) {
    PhotoToLoad p = new PhotoToLoad(url, imageView);
    executorService.submit(new PhotosLoader(p));
}

private Bitmap getBitmap(String url) {
    File f = fileCache.getFile(url);

    Bitmap b = decodeFile(f);
    if (b != null)
        return b;

    // Download Images from the Internet
    try {
        Bitmap bitmap = null;
        URL imageUrl = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) imageUrl
            .openConnection();
        conn.setConnectTimeout(30000);
        conn.setReadTimeout(30000);
        conn.setInstanceFollowRedirects(true);
        InputStream is = conn.getInputStream();
        OutputStream os = new FileOutputStream(f);
        Utils.CopyStream(is, os);
        os.close();
        conn.disconnect();
        bitmap = decodeFile(f);
        return bitmap;
    } catch (Throwable ex) {
        ex.printStackTrace();
        if (ex instanceof OutOfMemoryError)
            memoryCache.clear();
        return null;
    }
}

// Decodes image and scales it to reduce memory consumption
private Bitmap decodeFile(File f) {
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        FileInputStream stream1 = new FileInputStream(f);
        BitmapFactory.decodeStream(stream1, null, o);
        stream1.close();

        // Find the correct scale value. It should be the power of 2.
        final int REQUIRED_SIZE = 70;
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp / 2 < REQUIRED_SIZE
                || height_tmp / 2 < REQUIRED_SIZE)
                break;
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        FileInputStream stream2 = new FileInputStream(f);
        Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2);
        stream2.close();
        return bitmap;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

// Task for the queue
private class PhotoToLoad {
    public String url;
    public ImageView imageView;

    public PhotoToLoad(String u, ImageView i) {
        url = u;
        imageView = i;
    }
}

class PhotosLoader implements Runnable {
    PhotoToLoad photoToLoad;

    PhotosLoader(PhotoToLoad photoToLoad) {
        this.photoToLoad = photoToLoad;
    }

    @Override
    public void run() {
        try {
            if (imageViewReused(photoToLoad))
                return;
            Bitmap bmp = getBitmap(photoToLoad.url);
            memoryCache.put(photoToLoad.url, bmp);
            if (imageViewReused(photoToLoad))
                return;
            BitmapDisplayer bd = new BitmapDisplayer(bmp, photoToLoad);
            handler.post(bd);
        } catch (Throwable th) {
            th.printStackTrace();
        }
    }
}

boolean imageViewReused(PhotoToLoad photoToLoad) {
    String tag = imageViews.get(photoToLoad.imageView);
    if (tag == null || !tag.equals(photoToLoad.url))
        return true;
    return false;
}

// Used to display bitmap in the UI thread
class BitmapDisplayer implements Runnable {
    Bitmap bitmap;
    PhotoToLoad photoToLoad;

    public BitmapDisplayer(Bitmap b, PhotoToLoad p) {
        bitmap = b;
        photoToLoad = p;
    }

    public void run() {
        if (imageViewReused(photoToLoad))
            return;
        if (bitmap != null)
            photoToLoad.imageView.setImageBitmap(bitmap);
        else
            photoToLoad.imageView.setImageResource(stub_id);
    }
}

public void clearCache() {
    memoryCache.clear();
    fileCache.clear();
}

}

filecache.java

public class FileCache {

private File cacheDir;

public FileCache(Context context) {
    // Find the dir to save cached images
    if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED))
        cacheDir = new File(
            android.os.Environment.getExternalStorageDirectory(),
            "ImgTxt");
    else
        cacheDir = context.getCacheDir();
    if (!cacheDir.exists())
        cacheDir.mkdirs();
}

public File getFile(String url) {
    String filename = String.valueOf(url.hashCode());
    // String filename = URLEncoder.encode(url);
    File f = new File(cacheDir, filename);
    return f;

}

public void clear() {
    File[] files = cacheDir.listFiles();
    if (files == null)
        return;
    for (File f : files)
        f.delete();
}

}

memorycache.java

public class MemoryCache {

private static final String TAG = "MemoryCache";

// Last argument true for LRU ordering
private Map<String, Bitmap> cache = Collections
.synchronizedMap(new LinkedHashMap<String, Bitmap>(10, 1.5f, true));

// Current allocated size
private long size = 0;

// Max memory in bytes
private long limit = 1000000;

public MemoryCache() {
    // Use 25% of available heap size
    setLimit(Runtime.getRuntime().maxMemory() / 4);
}

public void setLimit(long new_limit) {
    limit = new_limit;
    Log.i(TAG, "MemoryCache will use up to " + limit / 1024. / 1024. + "MB");
}

public Bitmap get(String id) {
    try {
        if (!cache.containsKey(id))
            return null;
        return cache.get(id);
    } catch (NullPointerException ex) {
        ex.printStackTrace();
        return null;
    }
}

public void put(String id, Bitmap bitmap) {
    try {
        if (cache.containsKey(id))
            size -= getSizeInBytes(cache.get(id));
        cache.put(id, bitmap);
        size += getSizeInBytes(bitmap);
        checkSize();
    } catch (Throwable th) {
        th.printStackTrace();
    }
}

private void checkSize() {
    Log.i(TAG, "cache size=" + size + " length=" + cache.size());
    if (size > limit) {
        // Least recently accessed item will be the first one iterated
        Iterator<Entry<String, Bitmap>> iter = cache.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, Bitmap> entry = iter.next();
            size -= getSizeInBytes(entry.getValue());
            iter.remove();
            if (size <= limit)
                break;
        }
        Log.i(TAG, "Clean cache. New size " + cache.size());
    }
}

public void clear() {
    try {
        cache.clear();
        size = 0;
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
}

long getSizeInBytes(Bitmap bitmap) {
    if (bitmap == null)
        return 0;
    return bitmap.getRowBytes() * bitmap.getHeight();
}
}

android manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:name="ParseApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".SingleItemView">
    </activity>
</application>

</manifest>

解决方案

In the onclicklistener() add this code

intent.putExtra("levelimg",
                            (codeList.get(position).getLevelImg()));

                    intent.putExtra("heading",
                            (codeList.get(position).getSingleItemHeading()));

                    intent.putExtra("subheading",
                            (codeList.get(position).getDescription()));

                    intent.putExtra("apitext",
                            (codeList.get(position).getApiText()));

                    intent.putExtra("apiimg",
                            (codeList.get(position).getApiImg()));

                    intent.putExtra("descimgone",
                            (codeList.get(position).getPreviewImgOne()));

                    intent.putExtra("descimgtwo",
                            (codeList.get(position).getPreviewImgTwo()));

                    intent.putExtra("codetext",
                            (codeList.get(position).getFinalCodeText()));

这篇关于没有得到显示singleitem视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆