今天完成了广告界面的设计,
通过上网查询,了解到互联网广告投放一般按照天数计费,费用高低不一,通常有几种模式:季度收费,按年收费,天数计费等。
通过钟表计算广告运行的天数,来进行广告收益的计算,再将广告信息传输到数据库进行存储。
advertBean.java
package com.example.math.bean; public class advertBean { private String advert_name; private float price; private String time; public advertBean(String advert_name, float price, String time) { this.advert_name = advert_name; this.price = price; this.time = time; } public String getAdvert_name() { return advert_name; } public void setAdvert_name(String advert_name) { this.advert_name = advert_name; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } }
AdvertListAdapter.java//适配器
package com.example.math.adapter; import android.annotation.SuppressLint; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.example.math.R; import com.example.math.bean.advertBean; import java.util.List; public class AdvertListAdapter extends BaseAdapter { Context context; List<advertBean> mDataAdvert; LayoutInflater inflater; public AdvertListAdapter(Context context, List<advertBean> mDataAdvert) { this.context = context; this.mDataAdvert = mDataAdvert; inflater = LayoutInflater.from(context); } @Override public int getCount() { return mDataAdvert.size(); } @Override public Object getItem(int position) { return mDataAdvert.get(position); } @Override public long getItemId(int position) { return position; } @SuppressLint("SetTextI18n") @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder3 holder3 = null; if (convertView == null) { convertView = inflater.inflate(R.layout.advert_lv, parent, false); holder3 = new ViewHolder3(convertView); convertView.setTag(holder3); } else { holder3 = (ViewHolder3) convertView.getTag(); } advertBean bean = mDataAdvert.get(position); holder3.nameType.setText(bean.getAdvert_name() + ""); holder3.priceType.setText(bean.getPrice() + ""); holder3.timeType.setText(bean.getTime() + ""); return convertView; } static class ViewHolder3 { TextView nameType, priceType, timeType; public ViewHolder3(View view) { nameType = view.findViewById(R.id.advert_lv_name); priceType = view.findViewById(R.id.advert_lv_price); timeType = view.findViewById(R.id.advert_lv_time); } } }
AdvertActivity.java
package com.example.math; /* *广告界面 * */ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.view.WindowManager; import android.widget.ListView; import android.widget.TextView; import com.example.math.adapter.AdvertListAdapter; import com.example.math.bean.advertBean; import com.example.math.repositiory.Advert_res; import java.util.List; public class AdvertActivity extends AppCompatActivity { private ListView listView; private List<advertBean> mDataAdvert; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_advert); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); initData(); initListAdvert(); } private void initData() { TextView userName = findViewById(R.id.advert_name); CustomApplication app = (CustomApplication) getApplication(); String name = app.getValue(); userName.setText(name); listView = findViewById(R.id.advert_lv); } private void initListAdvert() { MyThread myThread = new MyThread(); Thread thread = new Thread(myThread); thread.start(); } private class MyThread implements Runnable{ @Override public void run() { TextView textView = findViewById(R.id.advert_name); String Names = textView.getText().toString(); try { mDataAdvert = Advert_res.advertBeans(Names); } catch (Exception e) { throw new RuntimeException(e); } Message msg = new Message(); msg.what = 1; myHandler.sendMessage(msg); } } private final Handler myHandler = new Handler(Looper.myLooper()){ @Override public void handleMessage(@NonNull Message msg) { if (msg.what ==1){ AdvertListAdapter adapter = new AdvertListAdapter(AdvertActivity.this,mDataAdvert); listView = findViewById(R.id.advert_lv); listView.setAdapter(adapter); } } }; @Override protected void onResume() { super.onResume(); initListAdvert(); } }
此页面为简单的listVIew视图页面。
标签:name,05,09,advert,2023,import,android,public,String From: https://www.cnblogs.com/JJTyyds/p/17385987.html