为什么不从Android SDK教程code开箱的? [英] Why doesn't the code from the Android SDK tutorials work out of the box?

查看:139
本文介绍了为什么不从Android SDK教程code开箱的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我失去了一些东西在这里?

Am I missing something here?

我照做此页面上的说明(以及其他一些教程),但他们似乎总是缺少,因为它们不开箱的一些关键的信息。

I follow the instructions exactly on this page (and some of the other tutorials) but they always seem to be missing some key information as they don't work out of the box.

我加了一堆好像失踪的包,但现在我卡住了。

I added a bunch of packages that seemed like were missing, but now I'm stuck.

http://developer.android.com/resources/tutorials/意见/ HELLO-gridview.html

描述资源路径位置类型
转换成Dalvik的格式失败,错误1 HelloGrid未知的Andr​​oid包装问题

和一大堆这些每个drawable.sample_的*引用

And a whole bunch of these for each of the drawable.sample_* references

描述资源路径位置类型
R.drawable.sample_0解决不了ImageAdapter.java / HelloGrid / src目录/ COM /例子/ ImageAdapter线51 Java问题

package com.example.HelloGrid;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.example.ImageAdapter.ImageAdapter;

public class HelloGrid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(HelloGrid.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}

package com.example.ImageAdapter;
import android.R;
import android.R.drawable;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return mThumbIds.length;
    }

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

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

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

    // references to our images
    private Integer[] mThumbIds = {
            R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4, R.drawable.sample_5,
            R.drawable.sample_6, R.drawable.sample_7,
            R.drawable.sample_0, R.drawable.sample_1,
            R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4, R.drawable.sample_5,
            R.drawable.sample_6, R.drawable.sample_7,
            R.drawable.sample_0, R.drawable.sample_1,
            R.drawable.sample_2, R.drawable.sample_3,
            R.drawable.sample_4, R.drawable.sample_5,
            R.drawable.sample_6, R.drawable.sample_7
    };
}

正如你可以看到我在/绘目录加载的所有图像

As you can see I have all the images loaded in the /drawable directory

推荐答案

它看起来像教程缺少一些的包信息,但如果你使用Eclipse应该处理大多数的你们。

It looks like the tutorials are missing some of the package information, but if you're using eclipse it should handle most of that for you.

这篇关于为什么不从Android SDK教程code开箱的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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