单击图像按钮时收到上述错误消息。我不确定这里的问题是什么。我要做的就是在文本框广告中分享文字。
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip">
<TextView
android:id="@+id/txtTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="normal|bold"
android:textSize="16dip"
android:padding="5dip"
android:text="Title"
android:textColor="#001a90" />
<TextView
android:id="@+id/txtDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="18dip"
android:padding="5dip"
android:text="Description"
android:textColor="#000000"
android:textIsSelectable="false" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/imageButton8"
android:layout_gravity="center_horizontal"
android:onClick="onClickShare" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:id="@+id/separator1"
android:visibility="visible"
android:background="@android:color/darker_gray"/>
</LinearLayout>
爪哇
public class rssitemview extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rssitemview);
}
public void onClickShare(View view){
TextView txtDesc = (TextView) findViewById(R.id.txtDescription);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, txtDesc.getText());
intent.setType("text/plain");
try {
startActivity(Intent.createChooser(intent, "Share Text..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(rssitemview.this, "There are no means to share.", Toast.LENGTH_SHORT).show();
}
startActivity(intent);
}
}
答案 0 :(得分:0)
解决方法是在ListAdaptor的getView类中添加OnClickListner。
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ImageButton whBtn = null;
ImageButton fbBtn = null;
ImageButton twBtn = null;
if(null == view)
{
LayoutInflater vi = (LayoutInflater)rssfeedFragment.this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.rssitemview, null);
whBtn = (ImageButton) view.findViewById(R.id.whBtn);
fbBtn = (ImageButton) view.findViewById(R.id.fbBtn);
twBtn = (ImageButton) view.findViewById(R.id.twBtn);
}
if (whBtn != null) {
whBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Code goes here
}
}
});
}
if (fbBtn != null) {
fbBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Code goes here
}
}
});
}
if (twBtn != null) {
twBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Code goes here
}
}
});
}