آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

بدست اوردن مقادیر یک custom controll

General  9 سال پیش  9 سال پیش
0 0

باسلام خدمت دوستان

من یه برنامه ای شبیه دیجی کالا دارم که میخوام برای هرمحصول پارامترهای اون محصول رو امتیاز دهی کنم

یعنی وقتی طرف میاد که به یه محصول من امتیاز بده اول برم چک بکنم ببینم این محصول چه پارامترهایی داره بعد به تعداد پارامترها یک کلاس امتیازدهی ایجاد کردم براش که میاد به تعداد اون پارامترها ازاین کلاس برای من توی اکتیویتیم میسازه

این کلاس custom control یه تکس ویو داره که نام پارامتر رو نشون میده ویکی دیگه هم یه ratingbar هست که میشه با کلیک برروش اون پارامتر رو امتیاز دهی کرد

این کدهای custom control:

public class CustomSetPoint extends LinearLayout {
public static TextView txtParamTitle;
public static RatingBar paramValue;
public static int point=0;

public CustomSetPoint(Context context) {
super(context);
init(context);
}
public CustomSetPoint(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public CustomSetPoint(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}

private void init(Context context) {
LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.custom_setpoint,this,true);



txtParamTitle=(TextView)view.findViewById(R.id.txtParamTitle);
paramValue=(RatingBar) view.findViewById(R.id.ratingParam);

paramValue.setOnRatingChangeListener(new RatingBar.OnRatingChangeListener() {
@Override
public void onRatingChange(float RatingCount) {


point=(float)RatingCount;

}
});
}
}



واینم کدهای اکتیویتیم که درش ازاین کلاس استفاده کردم:

 
public class ActivitySetPoint extends AppCompatActivity {

public static String data="";
LinearLayout.LayoutParams layoutParams;
LinearLayout linearSetPoint;
Button btnSend;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setpoint);
linearSetPoint=(LinearLayout)findViewById(R.id.linearSetPoint);
btnSend=(Button)findViewById(R.id.btnSend);


btnSend.setOnClickListener.....{

  1. //اینجا چی بنویسم تا بیاد مقدار point هر کاستوم کنترلم رو لاگ بکنه تا من بتونم بفرستمشون سمت سرور برای ذخیره در دیتابیس


}



Bundle bundle=getIntent().getExtras();
String id=bundle.getString("id");
//Toast.makeText(G.context,data,Toast.LENGTH_SHORT).show();

try {
JSONObject jsonObject=new JSONObject(data);
JSONArray params=new JSONArray(jsonObject.getString("title"));
for(int i=0;i<params.length();i++){
String titles=params.getString(i);

CustomSetPoint customSetPoint=new CustomSetPoint(G.context);
customSetPoint.txtParamTitle.setText(titles);

layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
linearSetPoint.addView(customSetPoint);


}






} catch (JSONException e) {
e.printStackTrace();
}


}
}


میخوام بدونم چطور میتونم وقتی روی دکمه ای که توی این اکتیویتی دارم کلیک کنم ومقادیر point هر کدوم ازاین کاستوم کنترلهارو بدست بیارم؟

ممنون از راهنمایی شما دوستان عزیز

0 0
کسی نمیتونه کمک کنه؟ (9 سال پیش)
 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .