小编Ahm*_*far的帖子

使用ArrayAdapter for ListView的OnItemClickListener

我想为我使用ArrayAdapter创建的ListView创建一个OnItemClickListener

这是我用来创建它的代码:

List<Comment> values = datasource.some_search("Wednesday","11");
        ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
                android.R.layout.simple_list_item_1, values);
        setListAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

我如何实现onItemClickListener?

谢谢!

编辑:我在我的ArrayAdapter和ListView中使用一串对象.

编辑2:更多代码:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        datasource = new CommentsDataSource(this);
        datasource.open();
        //check if database is populated if NOT, populate with txtToDb();

        if (!datasource.isPopulated()) {
            // Database is not populated so copy it from assets here
            try {
                txtToDb();
                Log.i("Database", "Was not Populated");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.i("Database", "Was not populated: txtToDb(); failed");

            }

        } …
Run Code Online (Sandbox Code Playgroud)

android listview onclick android-arrayadapter onitemclicklistener

21
推荐指数
2
解决办法
13万
查看次数

销毁克隆会破坏所有克隆

我想在一个特定的圆形区域内销毁一个对象的实例.代码如下:

Collider2D[] overlap = Physics2D.OverlapCircleAll(
    ball.transform.position, 
    (ball.renderer.bounds.size.x)/2);
if (overlap.Length>=1)
{           
    foreach (Collider2D coll in overlap)
    {
        Debug.Log (coll.GetInstanceID());
        if (coll.name.Contains("alien"))
        {
            //problem here:
            Destroy (coll.gameObject);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Destroy(coll.gameObject)破阵permanantly所有克隆和新的不实例化,我得到的错误MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

有没有办法摧毁那个特定的克隆?我尝试了不同的名称和使用,Destroy(GameObject.Find(coll.name))但也破坏了所有克隆,并防止新的产生.

有人帮忙吗?

更新:

实例化如下:

private bool bCanCreateParachuter = true; // bool to stop the …
Run Code Online (Sandbox Code Playgroud)

c# game-engine unity-game-engine unityscript

7
推荐指数
1
解决办法
1026
查看次数

SQLite查询小于或大于检查

我想用这个:

return mDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, 
KEY_LEVEL }, KEY_LEVEL + ">= 3 AND " + KEY_LEVEL + " < 5", null, null, null, null);
Run Code Online (Sandbox Code Playgroud)

但是,我希望它检查下一列找到大于或等于3的列,而不是5.

因此,当我输入5的输入时,我希望它在第3列中检查大于或等于5但小于下一列第4列中的值.

Sqlite查询检查中获取的原始代码- 小于和大于.

database sqlite algorithm android

4
推荐指数
1
解决办法
8053
查看次数