بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
قابلیت کلیک در ویو های سفارشی
سلام دوستان یک دکمه سفارشی ساختم اما می خوام وقتی روش کلیک می شه با یک متد از کلاسی دیگه براش رویدادی تعریف کنم کدهای فعلی به صورت زیر هست.
package com.slonz.pregnancy;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ViewButton extends LinearLayout {
private Context context;
private TextView textView;
private ImageView imageView;
private LinearLayout lin , layout1;
interface OnclickList{
void click();
}
public ViewButton(Context context , AttributeSet attributes){
super(context,attributes);
this.context = context;
initializer();
}
public ViewButton(Context context) {
super(context);
this.context = context;
initializer();
}
private void initializer() {
if (isInEditMode()) {
return;
}
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.view_button, this);
textView = (TextView) layout.findViewById(R.id.text);
imageView = (ImageView) layout.findViewById(R.id.img);
lin = (LinearLayout) layout.findViewById(R.id.layouter);
layout1 = (LinearLayout) layout.findViewById(R.id.border);
}
public void settxt(String text){
textView.setText(text);
}
برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال
سجاد
6 سال پیش
0
0
دوستان را حل این مسئله این بود که با یک رابط(interface) و یک متد به بالاترین لایه از طریق یک متد ارتباط ایجاد کرد با کلاس های دیگه ، کدی که جواب داد رو زیر می زارم ، دوستان این برای یک برنامه به نام بارداری هست که دارم می نویسم اگر ایده ای برای این برنامه دارید راهنمایی کنید ممنون.
package com.slonz.pregnancy;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ViewButton extends LinearLayout {
private Context context;
private TextView textView;
private ImageView imageView;
private LinearLayout lin , layout1;
public interface OnViewButtonClick{
void onClick();
}
public ViewButton(Context context , AttributeSet attributes){
super(context,attributes);
this.context = context;
initializer();
}
public ViewButton(Context context) {
super(context);
this.context = context;
initializer();
}
private void initializer() {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.view_button, this);
textView = (TextView) layout.findViewById(R.id.text);
imageView = (ImageView) layout.findViewById(R.id.img);
lin = (LinearLayout) layout.findViewById(R.id.layouter);
layout1 = (LinearLayout) layout.findViewById(R.id.border);
}
public void settxt(String text){
textView.setText(text);
}
public void setimage(int image){
imageView.setImageResource(image);
}
public void setbackgroundtext(int background){
textView.setBackground(getResources().getDrawable(background));
}
public void setbackgroundimage(int background){
lin.setBackground(getResources().getDrawable(background));
}
public void setborder(int drawable){
layout1.setBackground(getResources().getDrawable(drawable));
}
public void oncl(final OnViewButtonClick onViewButtonClick){ //متدی که صدا زده می شود تا از طریق رابط کلیک به لایه ایی که تمام لایه ها را در برگرفته دستوری بدهد.
layout1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
onViewButtonClick.onClick();
}
});
}
}
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .