Java ListView-can';t在TextView上投射意图

Java ListView-can';t在TextView上投射意图,java,android,list,android-intent,youtube,Java,Android,List,Android Intent,Youtube,我的应用程序有问题。首先,我将解释它应该如何工作。应用程序使用ListView当用户单击TextView时,它应该将用户从应用程序移动到youtube(例如,查看喜爱歌曲的音乐视频)。问题是用户点击TextView时,什么都没有发生,我应该在代码中更改什么 *现在,我不会通过类将链接传递到youtube,因为类应该将数据添加到列表中,现在,我只想一步一步地进行,我只是创建了带有视频链接的字符串 构造函数类 package com.example.kacper.recyclerview; pub

我的应用程序有问题。首先,我将解释它应该如何工作。应用程序使用ListView当用户单击TextView时,它应该将用户从应用程序移动到youtube(例如,查看喜爱歌曲的音乐视频)。问题是用户点击TextView时,什么都没有发生,我应该在代码中更改什么

*现在,我不会通过类将链接传递到youtube,因为类应该将数据添加到列表中,现在,我只想一步一步地进行,我只是创建了带有视频链接的字符串

构造函数类

package com.example.kacper.recyclerview;

public class Constructor {
private String mYoutubeLink;

public Constructor (String youtubeLink){
    mYoutubeLink = youtubeLink;
}

 public String getYoutubeLink(){return mYoutubeLink;}
}
适配器类

package com.example.kacper.recyclerview;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.zip.Inflater;

public class Adapter extends ArrayAdapter<Constructor> {
private Context context;
String id = "https://www.youtube.com/watch?v=JGwWNGJdvx8&list=RD87gWaABqGYs&index=4";

public Adapter(Activity context, ArrayList<Constructor> list) {
    super(context, 0, list);
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View list = convertView;
    if (list == null) {
        list = LayoutInflater.from(getContext()).inflate(R.layout.activity_list_item, parent, false);
    }

    TextView textView = (TextView) list.findViewById(R.id.TextView123);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
            context.startActivity(intent);
        }
    });

    return list;
}
package com.example.kacper.recyclerview;
导入android.app.Activity;
导入android.content.ActivityNotFoundException;
导入android.content.Context;
导入android.content.Intent;
导入android.net.Uri;
导入android.support.annotation.NonNull;
导入android.support.annotation.Nullable;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.TextView;
导入java.util.ArrayList;
导入java.util.zip.Inflater;
公共类适配器扩展了ArrayAdapter{
私人语境;
字符串id=”https://www.youtube.com/watch?v=JGwWNGJdvx8&list=RD87gWaABqGYs&index=4";
公共适配器(活动上下文、ArrayList列表){
超级(上下文,0,列表);
}
@非空
@凌驾
公共视图getView(int位置,@Nullable视图convertView,@NonNull视图组父级){
视图列表=转换视图;
if(list==null){
list=LayoutInflater.from(getContext()).flate(R.layout.activity\u list\u项,父项,false);
}
TextView TextView=(TextView)list.findViewById(R.id.TextView123);
textView.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Intent Intent=newintent(Intent.ACTION_视图,Uri.parse(“vnd.youtube://“+id));
背景。开始触觉(意图);
}
});
退货清单;
}
}

类,该类将包含数据并将其添加到列表中..:D

package com.example.kacper.recyclerview;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;

import java.util.ArrayList;

public class empty extends AppCompatActivity {
String string;

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

    ArrayList<Constructor> list = new ArrayList<Constructor>();
    list.add(new Constructor("dummy data"));
    Adapter adapter = new Adapter(this, list);

    ListView listView = (ListView) findViewById(R.id.list);
    listView.setAdapter(adapter);
}
}
package com.example.kacper.recyclerview;
导入android.content.Intent;
导入android.net.Uri;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.widget.ListView;
导入java.util.ArrayList;
公共类空扩展AppCompatActivity{
字符串字符串;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u list\u视图);
ArrayList=新建ArrayList();
添加(新构造函数(“虚拟数据”);
适配器=新适配器(此,列表);
ListView ListView=(ListView)findViewById(R.id.list);
setAdapter(适配器);
}
}
活动列表项目

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/TextView123"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="click"
    android:textSize="15sp"/>

</LinearLayout>

活动列表视图

<?xml version="1.0" encoding="utf-8"?>
<ListView
android:id="@+id/list"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>


我无法给出确切的答案,但我建议在getView和onClick方法中设置断点,以查看实际调用的内容。如果不知道问题在哪里,就很难诊断问题。您的ListView可能存在导致适配器无法调用的问题,或者触发intent的方式存在问题。如果您认为这是意图,我建议您在活动的onCreate方法中启动意图。

查看您的代码,您的适配器构造函数似乎需要更改为

public Adapter(Activity context, ArrayList<Constructor> list) {
    super(context, 0, list);
    this.context = context;
}

你还应该坚持发布R.layout.activity\u list\u项目的代码,请刚刚编辑过的帖子。你现在可以看到了。在我看来,可点击的视图非常小,请尝试增加文本视图的大小,然后再试一次。设置100 dp的宽度,并设置一个特定的高度,但仍然没有发生任何事情。所以。。有什么办法让它工作吗?:)好的,我会尝试用这些方法做一些事情。:)
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
context.startActivity(intent);