0
Я пишу приложение для Android, и мне нужна помощь с одной проблемой.Переместить товар в корзину Android
Цель:
- Добавить в корзину по кнопке постукивая со всеми атрибутами
У меня есть продукт, разборе из API (JSON)
Код:
string url2 = "http://new.murakami.ua/?mkapi=getProducts";
JsonValue json = await FetchAsync(url2);
ParseAndDisplay1(json);
ParseAndDisplay2(json);
ParseAndDisplay3(json);
ParseAndDisplay4(json);
ParseAndDisplay5(json);
ParseAndDisplay6(json);
ParseAndDisplay7(json);
ParseAndDisplay8(json);
private async Task<JsonValue> FetchAsync(string url)
{
// Create an HTTP web request using the URL:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.ContentType = "application/json";
request.Method = "GET";
// Send the request to the server and wait for the response:
using (WebResponse response = await request.GetResponseAsync())
{
// Get a stream representation of the HTTP web response:
using (Stream stream = response.GetResponseStream())
{
// Use this stream to build a JSON document object:
JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
//dynamic data = JObject.Parse(jsonDoc[15].ToString);
Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());
//string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
//string filename = System.IO.Path.Combine(path, "myfile.txt");
//using (var streamWriter = new StreamWriter(filename, true))
//{
// streamWriter.Write(jsonDoc.ToString());
// streamWriter.Close();
//}
// Return the JSON document:
return jsonDoc;
}
}
}
private void ParseAndDisplay1(JsonValue json)
{
TextView productname = FindViewById<TextView> (Resource.Id.posttittle);
TextView price = FindViewById<TextView> (Resource.Id.price);
TextView weight = FindViewById<TextView> (Resource.Id.weight);
productname.Click += delegate {
var intent404 = new Intent (this, typeof(SoupesDetailActivity1));
StartActivity (intent404);
};
JsonValue firstitem = json [81];
productname.Text = firstitem ["post_title"];
price.Text = firstitem ["price"] + " грн";
weight.Text = firstitem ["weight"] + "г";
}
И у меня есть макет в дизайне, который показывает поля (productname, price, weight)
код Axml:
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout12">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="147.6dp"
android:id="@+id/linearLayout13">
<ImageView
android:src="@drawable/sushi"
android:layout_width="123.1dp"
android:layout_height="match_parent"
android:id="@+id/image1"
android:background="#000" />
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="5dp"
android:layout_height="match_parent"
android:id="@+id/linearLayout14"
android:background="#cf8632" />
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="184.9dp"
android:layout_height="match_parent"
android:id="@+id/linearLayout15">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="181.9dp"
android:layout_height="63.3dp"
android:id="@+id/posttittle"
android:textColor="#ffffffff"
android:layout_marginLeft="7.7dp"
android:textSize="14sp"
android:clickable="true" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="93.8dp"
android:id="@+id/linearLayout16">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="48.7dp"
android:id="@+id/price"
android:layout_marginTop="39.8dp"
android:layout_marginLeft="5.5dp"
android:textColor="#ffffffff" />
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="58.8dp"
android:layout_height="53.3dp"
android:id="@+id/weight"
android:layout_marginLeft="21.5dp"
android:layout_marginTop="41.9dp"
android:textColor="#faaf56"
android:paddingTop="7dp" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:src="@drawable/cart2"
android:layout_width="wrap_content"
android:layout_height="57.1dp"
android:id="@+id/imageButton6"
android:layout_marginTop="34.8dp"
android:background="#00000000"
android:layout_marginLeft="2.4dp" />
Мне нужно создать это в новой деятельности (CartActivity и перемещать атрибуты продукта). Как я могу это сделать?
хорошо, как я могу генерировать axml кода в новой деятельности? –
, как и в первом действии, создайте папку xml под drawable-> layout и отправьте ее в setContentView вашей новой активности. –
Я знаю это. Я говорю о блоке для продукта. Когда я нажимаю кнопку, атрибуты передаются в новую активность, а блок автоматически генерируется Могу ли я это сделать или нет? –