Diễn đàn    Cổng thông tin , Chính phủ điện tử, VSP (VerySmart Portal), MVC Model View Controller, json, webapi    Xamarin android alert hien thi text

Thành viênTrả lời
thinhngheo


17  bài
4-7-2019 10:23:50
Hiện text thông báo :

Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
Android.App.AlertDialog alert = dialog.Create();
alert.SetTitle("Tieu de");
alert.SetMessage("Xin chao ban Khanh");
alert.SetButton("OK", (c, ev) =>
{
// Ok button click task
});
alert.Show();

Hiện text 3s rồi ẩn
Toast.MakeText(ApplicationContext, "Xin chao Khanhnd", ToastLength.Long).Show();
 
aspnet

Lập trình không biên giới
608  bài
4-7-2019 12:41:30
Hiển thị list sản phẩm :


ArrayList listProduct = new ArrayList();
listProduct.add(new Product(1, "Iphone 6", 500));
listProduct.add(new Product(2, "Iphone 7", 700));
listProduct.add(new Product(3, "Sony Abc", 800));
listProduct.add(new Product(4, "Samsung XYZ", 900));
listProduct.add(new Product(5, "SP 5", 500));
listProduct.add(new Product(6, "SP 6", 700));
listProduct.add(new Product(7, "SP 7", 800));
listProduct.add(new Product(8, "SP 8", 900));

final MyAdapter m_adapter = new MyAdapter(listProduct);
ListView listViewProduct = findViewById(R.id.products);
listViewProduct.setAdapter(m_adapter);

listViewProduct.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Product product = (Product) m_adapter.getItem(position);
//Làm gì đó khi chọn sản phẩm (ví dụ tạo một Activity hiện thị chi tiết, biên tập ..)
Toast.makeText(MainActivity.this, product.name, Toast.LENGTH_LONG).show();
}
});


MyAdapter thì viết thế này :

package com.example.ungdung;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class MyAdapter extends BaseAdapter {

final ArrayList<Product> listProduct;

MyAdapter(ArrayList<Product> listProduct) {
this.listProduct = listProduct;
}

@Override
public int getCount() {
//Trả về tổng số phần tử, nó được gọi bởi ListView
return listProduct.size();
}

@Override
public Object getItem(int position) {
//Trả về dữ liệu ở vị trí position của Adapter, tương ứng là phần tử
//có chỉ số position trong listProduct
return listProduct.get(position);
}

@Override
public long getItemId(int position) {
//Trả về một ID của phần
return listProduct.get(position).productID;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
//convertView là View của phần tử ListView, nếu convertView != null nghĩa là
//View này được sử dụng lại, chỉ việc cập nhật nội dung mới
//Nếu null cần tạo mới

View viewProduct;
if (convertView == null) {
viewProduct = View.inflate(parent.getContext(), R.layout.product_view, null);
} else viewProduct = convertView;

//Bind sữ liệu phần tử vào View
Product product = (Product) getItem(position);
((TextView) viewProduct.findViewById(R.id.idproduct)).setText(String.format("ID = %d", product.productID));
((TextView) viewProduct.findViewById(R.id.nameproduct)).setText(String.format("Tên SP : %s", product.name));
((TextView) viewProduct.findViewById(R.id.priceproduct)).setText(String.format("Giá %d", product.price));


return viewProduct;
}
}

Class Product thì thế này :

package com.example.ungdung;

class Product {
String name;
int price;
int productID;

public Product(int productID, String name, int price) {
this.name = name;
this.price = price;
this.productID = productID;
}
}
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 

Chủ đề gần đây :

Cùng loại :

Tên file Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM